Skip to content

Commit 1cb6c10

Browse files
updated vendored code with upstream: github:/andyk/ht/pull/25
1 parent 117c3f5 commit 1cb6c10

File tree

11 files changed

+67
-26
lines changed

11 files changed

+67
-26
lines changed

htty-core/Cargo.lock

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

htty-core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ path = "src/rust/main.rs"
2626
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2727

2828
[dependencies]
29-
avt = "0.11.1"
29+
avt = "0.16.0"
3030
nix = { version = "0.28.0", features = ["term", "process", "fs", "signal"] }
3131
serde_json = "1.0.117"
3232
mio = { version = "0.8.11", features = ["os-poll", "os-ext"] }
3333
anyhow = "1.0.81"
34-
serde = "1.0.203"
34+
serde = { version = "1.0.203", features = ["derive"] }
3535
tokio = { version = "1.38.0", features = ["full"] }
3636
axum = { version = "0.7.5", default-features = false, features = ["http1", "ws", "query"] }
3737
tokio-stream = { version = "0.1.15", features = ["sync"] }

htty-core/pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ classifiers = [
2828
]
2929

3030
[project.urls]
31-
Homepage = "https://github.com/MatrixManAtYrService/ht"
32-
Documentation = "https://github.com/MatrixManAtYrService/ht"
33-
Repository = "https://github.com/MatrixManAtYrService/ht"
34-
Issues = "https://github.com/MatrixManAtYrService/ht/issues"
31+
Homepage = "https://github.com/MatrixManAtYrService/htty"
32+
Documentation = "https://MatrixManAtYrService.github.io/htty/htty.html"
33+
Repository = "https://github.com/MatrixManAtYrService/htty"
34+
Issues = "https://github.com/MatrixManAtYrService/htty/issues"
3535

3636
[build-system]
3737
requires = ["maturin>=1.3.2"]
@@ -123,4 +123,4 @@ reportUntypedFunctionDecorator = "error"
123123
reportUntypedClassDecorator = "error"
124124
reportUntypedBaseClass = "error"
125125
reportUntypedNamedTuple = "error"
126-
# [[[end]]]
126+
# [[[end]]]

htty-core/src/rust/api/http.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async fn alis_message(
8686
use session::Event::*;
8787

8888
match event {
89-
Ok(Init(time, cols, rows, seq, _text)) => Some(Ok(json_message(json!({
89+
Ok(Init(time, cols, rows, _pid, seq, _text)) => Some(Ok(json_message(json!({
9090
"time": time,
9191
"cols": cols,
9292
"rows": rows,
@@ -166,7 +166,7 @@ async fn event_stream_message(
166166
use session::Event::*;
167167

168168
match event {
169-
Ok(e @ Init(_, _, _, _, _)) if sub.init => Some(Ok(json_message(e.to_json()))),
169+
Ok(e @ Init(..)) if sub.init => Some(Ok(json_message(e.to_json()))),
170170
Ok(e @ Output(_, _)) if sub.output => Some(Ok(json_message(e.to_json()))),
171171
Ok(e @ Resize(_, _, _)) if sub.resize => Some(Ok(json_message(e.to_json()))),
172172
Ok(e @ Snapshot(_, _, _, _)) if sub.snapshot => Some(Ok(json_message(e.to_json()))),

htty-core/src/rust/api/stdio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub async fn start(
7676
use session::Event::*;
7777

7878
match event {
79-
Some(Ok(e @ Init(_, _, _, _, _))) if sub.init => {
79+
Some(Ok(e @ Init(..))) if sub.init => {
8080
println!("{}", e.to_json());
8181
}
8282

htty-core/src/rust/cli.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,33 @@ use anyhow::{bail, Result};
33
use nix::pty;
44
use std::{fmt::Display, net::SocketAddr, ops::Deref, str::FromStr, path::PathBuf, env};
55

6+
#[derive(Debug, Clone, Copy, Default)]
7+
pub enum StyleMode {
8+
#[default]
9+
Plain,
10+
Styled,
11+
}
12+
13+
impl FromStr for StyleMode {
14+
type Err = String;
15+
16+
fn from_str(s: &str) -> Result<Self, Self::Err> {
17+
match s.to_lowercase().as_str() {
18+
"plain" => Ok(StyleMode::Plain),
19+
"styled" => Ok(StyleMode::Styled),
20+
_ => Err(format!("invalid style mode: {s}. Valid options: plain, styled")),
21+
}
22+
}
23+
}
24+
625
#[derive(Debug)]
726
pub struct Cli {
827
pub command: Option<Commands>,
928
pub size: Size,
1029
pub shell_command: Vec<String>,
1130
pub listen: Option<SocketAddr>,
1231
pub subscribe: Option<Subscription>,
32+
pub style_mode: StyleMode,
1333
}
1434

1535
#[derive(Debug)]
@@ -33,6 +53,7 @@ fn parse_args(args: &[String]) -> Result<Cli> {
3353
shell_command: vec!["bash".to_string()],
3454
listen: None,
3555
subscribe: None,
56+
style_mode: StyleMode::default(),
3657
};
3758

3859
let mut i = 1; // Skip program name
@@ -75,6 +96,13 @@ fn parse_args(args: &[String]) -> Result<Cli> {
7596
i += 1;
7697
cli.subscribe = Some(args[i].parse().map_err(|e: String| anyhow::anyhow!(e))?);
7798
}
99+
"--style-mode" | "-s" => {
100+
if i + 1 >= args.len() {
101+
bail!("--style-mode requires a value");
102+
}
103+
i += 1;
104+
cli.style_mode = args[i].parse().map_err(|e: String| anyhow::anyhow!(e))?;
105+
}
78106
"wait-exit" => {
79107
if i + 1 >= args.len() {
80108
bail!("wait-exit requires a signal file path");
@@ -122,6 +150,7 @@ fn print_help(program_name: &str) {
122150
println!(" --size <COLSxROWS> Terminal size [default: 120x40]");
123151
println!(" -l, --listen [<LISTEN_ADDR>] Enable HTTP server");
124152
println!(" --subscribe <EVENTS> Subscribe to events");
153+
println!(" -s, --style-mode <MODE> Style mode for snapshots [default: plain]");
125154
println!(" -h, --help Print help");
126155
println!(" -V, --version Print version");
127156
}

htty-core/src/rust/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async fn main() -> Result<()> {
3737
start_http_api(cli.listen, clients_tx.clone()).await?;
3838
let api = start_stdio_api(command_tx.clone(), clients_tx, cli.subscribe.unwrap_or_default());
3939
let pty = start_pty(cli.shell_command.clone(), &cli.size, input_rx, output_tx, pid_tx, exit_code_tx, command_tx.clone())?;
40-
let session = build_session(&cli.size);
40+
let session = build_session(&cli.size, cli.style_mode);
4141
run_event_loop(output_rx, input_tx, command_rx, clients_rx, pid_rx, exit_code_rx, session, api, &cli).await?;
4242
pty.await?
4343
}
@@ -68,8 +68,10 @@ async fn handle_waitexit(signal_file: PathBuf) -> Result<()> {
6868
Ok(())
6969
}
7070

71-
fn build_session(size: &cli::Size) -> Session {
72-
Session::new(size.cols(), size.rows())
71+
fn build_session(size: &cli::Size, style_mode: cli::StyleMode) -> Session {
72+
let mut session = Session::new(size.cols(), size.rows());
73+
session.set_style_mode(style_mode);
74+
session
7375
}
7476

7577
fn start_stdio_api(

htty-core/src/rust/session.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::cli::StyleMode;
12
use anyhow::Result;
23
use futures_util::{stream, Stream, StreamExt};
34
use serde_json::json;
@@ -13,11 +14,12 @@ pub struct Session {
1314
start_time: Instant,
1415
last_event_time: Instant,
1516
pending_pid: Option<i32>,
17+
style_mode: StyleMode,
1618
}
1719

1820
#[derive(Clone, Debug)]
1921
pub enum Event {
20-
Init(f64, usize, usize, String, String),
22+
Init(f64, usize, usize, i32, String, String),
2123
Output(f64, String),
2224
Resize(f64, usize, usize),
2325
Snapshot(usize, usize, String, String),
@@ -46,6 +48,7 @@ impl Session {
4648
start_time: now,
4749
last_event_time: now,
4850
pending_pid: None,
51+
style_mode: StyleMode::Plain,
4952
}
5053
}
5154

@@ -107,7 +110,11 @@ impl Session {
107110
}
108111

109112
pub fn cursor_key_app_mode(&self) -> bool {
110-
self.vt.arrow_key_app_mode()
113+
self.vt.cursor_key_app_mode()
114+
}
115+
116+
pub fn set_style_mode(&mut self, style_mode: StyleMode) {
117+
self.style_mode = style_mode;
111118
}
112119

113120
pub fn subscribe(&self) -> Subscription {
@@ -117,6 +124,7 @@ impl Session {
117124
self.elapsed_time(),
118125
cols,
119126
rows,
127+
self.pending_pid.unwrap_or(0),
120128
self.vt.dump(),
121129
self.text_view(),
122130
);
@@ -148,11 +156,12 @@ impl Session {
148156
impl Event {
149157
pub fn to_json(&self) -> serde_json::Value {
150158
match self {
151-
Event::Init(_time, cols, rows, seq, text) => json!({
159+
Event::Init(_time, cols, rows, pid, seq, text) => json!({
152160
"type": "init",
153161
"data": json!({
154162
"cols": cols,
155163
"rows": rows,
164+
"pid": pid,
156165
"seq": seq,
157166
"text": text,
158167
})
@@ -215,7 +224,7 @@ impl Event {
215224
}
216225

217226
fn build_vt(cols: usize, rows: usize) -> avt::Vt {
218-
avt::Vt::builder().size(cols, rows).resizable(true).build()
227+
avt::Vt::builder().size(cols, rows).build()
219228
}
220229

221230
fn resize_vt(vt: &mut avt::Vt, cols: usize, rows: usize) {

htty/pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ dependencies = [
5151
]
5252

5353
[project.urls]
54-
Homepage = "https://github.com/MatrixManAtYrService/ht"
55-
Documentation = "https://github.com/MatrixManAtYrService/ht"
56-
Repository = "https://github.com/MatrixManAtYrService/ht"
57-
Issues = "https://github.com/MatrixManAtYrService/ht/issues"
54+
Homepage = "https://github.com/MatrixManAtYrService/htty"
55+
Documentation = "https://MatrixManAtYrService.github.io/htty/htty.html"
56+
Repository = "https://github.com/MatrixManAtYrService/htty"
57+
Issues = "https://github.com/MatrixManAtYrService/htty/issues"
5858

5959
[project.scripts]
6060
htty = "htty.cli:htty_sync"

nix/lib/cog-env.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
let
66
version = import ./version.nix { inherit pkgs; };
7-
in {
7+
in
8+
{
89
HTTY_VERSION = version.version;
910
HTTY_COMMON_RUFF_TOML = builtins.readFile ../../common/ruff.toml;
1011
HTTY_COMMON_PYRIGHT_TOML = builtins.readFile ../../common/pyright.toml;
11-
}
12+
}

0 commit comments

Comments
 (0)