Skip to main content

Options

Struct Options 

Source
pub struct Options {
    pub app: Option<String>,
    pub version: Option<String>,
    pub features: Vec<String>,
    pub timeout: Duration,
    pub bracketed_paste: bool,
    pub kitty_keyboard: bool,
    pub record: Option<PathBuf>,
}
Expand description

How to connect.

Fields§

§app: Option<String>

The program’s name (default: the executable’s).

§version: Option<String>

The program’s version.

§features: Vec<String>

Program features (edit, undo, send).

§timeout: Duration

How long to wait for the hello reply.

§bracketed_paste: bool

Enable bracketed paste while connected.

§kitty_keyboard: bool

Push the kitty keyboard flag 1 while connected.

§record: Option<PathBuf>

Record every message as JSONL (default: TERN_TSP_RECORD).

Implementations§

Source§

impl Options

Source

pub fn new() -> Self

The defaults.

Examples found in repository?
examples/progress.rs (line 102)
101fn main() -> Result<(), tern_sdk::Error> {
102	let Some(mut session) = Session::connect(Options::new())? else {
103		for (i, step) in STEPS.iter().enumerate() {
104			println!("[{}/{}] {step}", i + 1, STEPS.len());
105			std::thread::sleep(STEP);
106		}
107		println!("Built demo.");
108		return Ok(());
109	};
110	let start = Instant::now();
111	let sf = session.open(SurfaceOptions::flow().title("progress"))?;
112	let mut build =
113		Build { log: String::new(), done: 0, took: None, status: Status::Running };
114	session.render(sf, view(&build))?;
115	for step in STEPS {
116		if wait(&mut session, STEP)? {
117			build.status = Status::Cancelled;
118			break;
119		}
120		build.log.push_str("\x1b[32m✓\x1b[0m ");
121		build.log.push_str(step);
122		build.log.push_str("\r\n");
123		build.done += 1;
124		session.render(sf, view(&build))?;
125	}
126	if build.status == Status::Running {
127		build.status = Status::Done;
128	}
129	let took = start.elapsed();
130	build.took = Some(took.as_millis() as u64);
131	session.render(sf, view(&build))?;
132	session.close()?;
133	match build.status {
134		Status::Done => println!("Built demo in {:.1}s.", took.as_secs_f64()),
135		_ => println!("Build cancelled."),
136	}
137	Ok(())
138}
More examples
Hide additional examples
examples/chat.rs (line 128)
127fn main() -> Result<(), tern_sdk::Error> {
128	let Some(mut session) = Session::connect(Options::new().feature(feature::SEND))? else {
129		println!("chat needs a terminal that speaks TSP (Tern).");
130		return Ok(());
131	};
132	let sf = session.open(SurfaceOptions::inline().title("chat"))?;
133	let mut chat = Chat::default();
134	session.render(sf, chat.view())?;
135	session.focus(sf, Some(EDITOR))?;
136	while let Some(input) = session.next(None)? {
137		match input {
138			Input::Key(key) => {
139				if key.is("escape") || key.is("ctrl+c") || key.is("ctrl+d") {
140					break;
141				}
142				match key.name.as_str() {
143					"enter" if !key.shift && !key.alt => {
144						let text = std::mem::take(&mut chat.draft);
145						chat.cursor = 0;
146						chat.send(text);
147					},
148					"enter" => chat.insert("\n"),
149					"backspace" if chat.cursor > 0 => {
150						let at = chat.byte(chat.cursor - 1);
151						chat.draft.remove(at);
152						chat.cursor -= 1;
153					},
154					"delete" if chat.cursor < chat.draft.chars().count() => {
155						let at = chat.byte(chat.cursor);
156						chat.draft.remove(at);
157					},
158					"left" => chat.cursor = chat.cursor.saturating_sub(1),
159					"right" => chat.cursor = (chat.cursor + 1).min(chat.draft.chars().count()),
160					"home" => chat.cursor = 0,
161					"end" => chat.cursor = chat.draft.chars().count(),
162					"paste" => chat.insert(key.text.as_deref().unwrap_or_default()),
163					_ => match key.typed() {
164						Some(text) => chat.insert(text),
165						None => continue,
166					},
167				}
168			},
169			Input::Msg(Msg::Send(text), _) => chat.send(text),
170			Input::Msg(Msg::Focus, _) => session.focus(sf, Some(EDITOR))?,
171			Input::Event(_) => continue,
172		}
173		session.render(sf, chat.view())?;
174	}
175	session.close()?;
176	println!("Chat closed after {} messages.", chat.transcript.len());
177	Ok(())
178}
Source

pub fn app(self, app: impl Into<String>) -> Self

Sets the program’s name.

Source

pub fn version(self, version: impl Into<String>) -> Self

Sets the program’s version.

Source

pub fn feature(self, feature: impl Into<String>) -> Self

Adds a program feature (crate::wire::feature).

Examples found in repository?
examples/chat.rs (line 128)
127fn main() -> Result<(), tern_sdk::Error> {
128	let Some(mut session) = Session::connect(Options::new().feature(feature::SEND))? else {
129		println!("chat needs a terminal that speaks TSP (Tern).");
130		return Ok(());
131	};
132	let sf = session.open(SurfaceOptions::inline().title("chat"))?;
133	let mut chat = Chat::default();
134	session.render(sf, chat.view())?;
135	session.focus(sf, Some(EDITOR))?;
136	while let Some(input) = session.next(None)? {
137		match input {
138			Input::Key(key) => {
139				if key.is("escape") || key.is("ctrl+c") || key.is("ctrl+d") {
140					break;
141				}
142				match key.name.as_str() {
143					"enter" if !key.shift && !key.alt => {
144						let text = std::mem::take(&mut chat.draft);
145						chat.cursor = 0;
146						chat.send(text);
147					},
148					"enter" => chat.insert("\n"),
149					"backspace" if chat.cursor > 0 => {
150						let at = chat.byte(chat.cursor - 1);
151						chat.draft.remove(at);
152						chat.cursor -= 1;
153					},
154					"delete" if chat.cursor < chat.draft.chars().count() => {
155						let at = chat.byte(chat.cursor);
156						chat.draft.remove(at);
157					},
158					"left" => chat.cursor = chat.cursor.saturating_sub(1),
159					"right" => chat.cursor = (chat.cursor + 1).min(chat.draft.chars().count()),
160					"home" => chat.cursor = 0,
161					"end" => chat.cursor = chat.draft.chars().count(),
162					"paste" => chat.insert(key.text.as_deref().unwrap_or_default()),
163					_ => match key.typed() {
164						Some(text) => chat.insert(text),
165						None => continue,
166					},
167				}
168			},
169			Input::Msg(Msg::Send(text), _) => chat.send(text),
170			Input::Msg(Msg::Focus, _) => session.focus(sf, Some(EDITOR))?,
171			Input::Event(_) => continue,
172		}
173		session.render(sf, chat.view())?;
174	}
175	session.close()?;
176	println!("Chat closed after {} messages.", chat.transcript.len());
177	Ok(())
178}
Source

pub const fn timeout(self, timeout: Duration) -> Self

Sets the handshake timeout.

Source

pub const fn bracketed_paste(self, on: bool) -> Self

Turns bracketed paste on or off.

Source

pub const fn kitty_keyboard(self, on: bool) -> Self

Turns the kitty keyboard flag on or off.

Source

pub fn record(self, path: Option<PathBuf>) -> Self

Records to path (or not).

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Options

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Options

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more