summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock29
-rw-r--r--Cargo.toml2
-rw-r--r--src/history.rs4
-rw-r--r--src/readline.rs45
4 files changed, 67 insertions, 13 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7b8e735..c54771a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -315,6 +315,17 @@ dependencies = [
]
[[package]]
+name = "hostname"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867"
+dependencies = [
+ "libc",
+ "match_cfg",
+ "winapi",
+]
+
+[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -370,6 +381,12 @@ dependencies = [
]
[[package]]
+name = "match_cfg"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4"
+
+[[package]]
name = "memchr"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -392,6 +409,7 @@ dependencies = [
"async-std",
"chrono",
"futures-lite",
+ "hostname",
"libc",
"nix",
"pty-process",
@@ -400,6 +418,7 @@ dependencies = [
"terminal_size",
"textmode",
"unicode-width",
+ "users",
"vt100",
]
@@ -636,6 +655,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
+name = "users"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
+dependencies = [
+ "libc",
+ "log",
+]
+
+[[package]]
name = "utf8parse"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 649f174..c873200 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,6 +10,7 @@ anyhow = "1.0.45"
async-std = { version = "1.10.0", features = ["unstable"] }
chrono = "0.4.19"
futures-lite = "1.12.0"
+hostname = "0.3.1"
libc = "0.2.107"
nix = "0.23.0"
pty-process = { path = "../pty-process", version = "0.1.1", features = ["backend-async-std"] }
@@ -18,6 +19,7 @@ signal-hook-async-std = "0.2.1"
terminal_size = "0.1.17"
textmode = { path = "../textmode", version = "0.1.1", features = ["async"] }
unicode-width = "0.1.9"
+users = "0.11.0"
vt100 = { path = "../vt100-rust", version = "0.12.0" }
[features]
diff --git a/src/history.rs b/src/history.rs
index 1136821..5bd377a 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -272,13 +272,15 @@ impl HistoryEntry {
out.set_fgcolor(textmode::color::RED);
}
out.write_str(&crate::format::exit_status(info.status));
- out.reset_attributes();
} else {
out.write_str(" ");
}
+ out.reset_attributes();
if focused {
out.set_fgcolor(textmode::color::BLACK);
out.set_bgcolor(textmode::color::CYAN);
+ } else {
+ out.set_bgcolor(textmode::Color::Rgb(32, 32, 32));
}
out.write_str("$ ");
out.reset_attributes();
diff --git a/src/readline.rs b/src/readline.rs
index be05533..9fa137b 100644
--- a/src/readline.rs
+++ b/src/readline.rs
@@ -59,7 +59,7 @@ impl Readline {
}
pub fn lines(&self) -> usize {
- 1 // XXX handle wrapping, multiline prompts
+ 2 // XXX handle wrapping
}
pub async fn render(
@@ -67,6 +67,37 @@ impl Readline {
out: &mut textmode::Output,
focus: bool,
) -> anyhow::Result<()> {
+ let mut pwd = std::env::current_dir()?.display().to_string();
+ let home = std::env::var("HOME")?;
+ if pwd.starts_with(&home) {
+ pwd.replace_range(..home.len(), "~");
+ }
+ let user = users::get_current_username()
+ .unwrap()
+ .to_string_lossy()
+ .into_owned();
+ let mut hostname =
+ hostname::get().unwrap().to_string_lossy().into_owned();
+ if let Some(idx) = hostname.find('.') {
+ hostname.truncate(idx);
+ }
+ let id = format!("{}@{}", user, hostname);
+ let idlen: u16 = id.len().try_into().unwrap();
+ let time = chrono::Local::now().format("%H:%M:%S").to_string();
+ let timelen: u16 = time.len().try_into().unwrap();
+
+ out.move_to(self.size.0 - 2, 0);
+ out.set_bgcolor(textmode::Color::Rgb(32, 32, 32));
+ out.write(b"\x1b[K");
+ out.write(b" (");
+ out.write_str(&pwd);
+ out.write(b")");
+ out.move_to(self.size.0 - 2, self.size.1 - 4 - idlen - timelen);
+ out.write_str(&id);
+ out.write_str(" [");
+ out.write_str(&time);
+ out.write_str("]");
+
out.move_to(self.size.0 - 1, 0);
if focus {
out.set_fgcolor(textmode::color::BLACK);
@@ -77,14 +108,8 @@ impl Readline {
out.write_str(&self.prompt);
out.reset_attributes();
out.set_bgcolor(textmode::Color::Rgb(32, 32, 32));
+ out.write(b"\x1b[K");
out.write_str(&self.input_line);
- out.write_str(
- &" ".repeat(
- (self.size.1 - self.prompt_width() - self.input_line_width())
- .try_into()
- .unwrap(),
- ),
- );
out.reset_attributes();
out.move_to(self.size.0 - 1, self.prompt_width() + self.pos_width());
if focus {
@@ -159,10 +184,6 @@ impl Readline {
self.prompt.width().try_into().unwrap()
}
- fn input_line_width(&self) -> u16 {
- self.input_line.width().try_into().unwrap()
- }
-
fn pos_width(&self) -> u16 {
self.input_line
.chars()