Skip to content

Commit

Permalink
add support for starting in a specific directory
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiyaa committed Oct 24, 2021
1 parent 1af1670 commit 153c722
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 42 deletions.
2 changes: 1 addition & 1 deletion config/client.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ home_dir = "~/music"
[client.display]
show_borders = true
show_hidden = false
layout = "~/.config/layout.json"
layout = "~/.config/dizi/layout.json"

[client.display.sort]
reverse = false
Expand Down
5 changes: 5 additions & 0 deletions config/keymap.toml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ keys = [ "d" ]
command = "server_request"
json.request = "/playlist/remove"

[[keymap]]
keys = [ "C" ]
command = "server_request"
json.request = "/playlist/clear"

[[keymap]]
keys = [ "w" ]
command = "server_request"
Expand Down
62 changes: 32 additions & 30 deletions config/layout.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
{
"type": "composite"
"direction": "horizontal"
"ratio": 1
"widgets": [
{
"type": "simple"
"widget": "file_browser"
"ratio": 1
"border": true
},
{
"type": "composite"
"direction": "vertical"
"ratio": 1
"widgets": [
{
"type": "simple"
"widget": "music_player"
"ratio": 2
"border": true
},
{
"type": "simple"
"widget": "playlist"
"ratio": 3
"border": true
}
]
}
]
"layout": {
"type": "composite",
"direction": "horizontal",
"ratio": 1,
"widgets": [
{
"type": "simple",
"widget": "file_browser",
"ratio": 1,
"border": true
},
{
"type": "composite",
"direction": "vertical",
"ratio": 1,
"widgets": [
{
"type": "simple",
"widget": "music_player",
"ratio": 2,
"border": true
},
{
"type": "simple",
"widget": "playlist",
"ratio": 3,
"border": true
}
]
}
]
}
}
10 changes: 9 additions & 1 deletion config/server.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
[server]
socket = "/tmp/dizi-server-socket"

# Where to save playlist on exit
playlist = "~/.config/dizi/playlist.m3u"

# not implemented
poll_rate = 200

# run a script whenever the song changes
# on_song_change = "some_script"

[server.player]
# supports alsa, jack
audio_system = "alsa"

shuffle = false
repeat = true
next = true
# on_song_change = ""

58 changes: 55 additions & 3 deletions config/theme.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
[selection]
fg = "light_yellow"
bold = true
[selection.prefix]
prefix = " "
size = 2

[executable]
fg = "light_green"
bold = true

[regular]
fg = "white"

Expand All @@ -9,10 +20,34 @@ bold = true
fg = "cyan"
bold = true

[link_invalid]
fg = "red"
bold = true

[socket]
fg = "light_magenta"
bold = true

[ext]

[ext.m3u8]
fg = "red"
[ext.bmp]
fg = "yellow"
[ext.heic]
fg = "yellow"
[ext.jpg]
fg = "yellow"
[ext.jpeg]
fg = "yellow"
[ext.pgm]
fg = "yellow"
[ext.png]
fg = "yellow"
[ext.ppm]
fg = "yellow"
[ext.svg]
fg = "yellow"
[ext.gif]
fg = "yellow"

[ext.wav]
fg = "magenta"
Expand All @@ -23,7 +58,7 @@ fg = "magenta"
[ext.avi]
fg = "magenta"
[ext.m3u]
fg = "magenta"
fg = "red"
[ext.mov]
fg = "magenta"
[ext.m4v]
Expand All @@ -40,3 +75,20 @@ fg = "magenta"
fg = "magenta"
[ext.wmv]
fg = "magenta"

[ext.7z]
fg = "red"
[ext.zip]
fg = "red"
[ext.bz2]
fg = "red"
[ext.gz]
fg = "red"
[ext.tar]
fg = "red"
[ext.tgz]
fg = "red"
[ext.xz]
fg = "red"
[ext.rar]
fg = "red"
23 changes: 16 additions & 7 deletions src/client/config/general/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::convert::From;
use std::path::PathBuf;

use serde_derive::Deserialize;
use shellexpand::tilde_with_context;

use crate::config::option::DisplayOption;

Expand All @@ -16,7 +17,7 @@ pub struct ClientConfigCrude {
#[serde(default)]
pub socket: String,
#[serde(default)]
pub home_dir: String,
pub home_dir: Option<String>,

#[serde(default, rename = "display")]
pub display_options: DisplayOptionCrude,
Expand All @@ -26,17 +27,25 @@ impl std::default::Default for ClientConfigCrude {
fn default() -> Self {
Self {
socket: "".to_string(),
home_dir: "".to_string(),
home_dir: None,
display_options: DisplayOptionCrude::default(),
}
}
}

impl From<ClientConfigCrude> for ClientConfig {
fn from(crude: ClientConfigCrude) -> Self {

let socket = PathBuf::from(tilde_with_context(&crude.socket, dirs_next::home_dir).as_ref());
let home_dir = if let Some(home_dir) = crude.home_dir {
Some(PathBuf::from(tilde_with_context(&home_dir, dirs_next::home_dir).as_ref()))
} else {
None
};

Self {
socket: PathBuf::from(crude.socket),
home_dir: PathBuf::from(crude.home_dir),
socket,
home_dir,
display_options: DisplayOption::from(crude.display_options),
}
}
Expand All @@ -45,7 +54,7 @@ impl From<ClientConfigCrude> for ClientConfig {
#[derive(Clone, Debug)]
pub struct ClientConfig {
pub socket: PathBuf,
pub home_dir: PathBuf,
pub home_dir: Option<PathBuf>,
pub display_options: DisplayOption,
}

Expand All @@ -58,8 +67,8 @@ impl ClientConfig {
impl std::default::Default for ClientConfig {
fn default() -> Self {
Self {
socket: PathBuf::from(""),
home_dir: PathBuf::from(""),
socket: PathBuf::from("/tmp/dizi-server-socket"),
home_dir: None,
display_options: DisplayOption::default(),
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/client/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ fn run_app(args: Args) -> DiziResult<()> {
}
let stream = UnixStream::connect(&config.client_ref().socket)?;

if let Some(home_dir) = config.client_ref().home_dir.as_ref() {
std::env::set_current_dir(home_dir)?;
}
let cwd = std::env::current_dir()?;
let mut context = AppContext::new(config, cwd.clone(), stream);

Expand Down

0 comments on commit 153c722

Please sign in to comment.