Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

shift+enter in cli (#1040)

uuuvn78f1bcad842c
diff --git a/crates/legacy/cli/src/interactive/components/application.rs b/crates/legacy/cli/src/interactive/components/application.rs
index 37c4e5e04..137c3b97c 100644
--- a/crates/legacy/cli/src/interactive/components/application.rs
+++ b/crates/legacy/cli/src/interactive/components/application.rs
@@ -17,6 +17,7 @@ use crate::{
components::{CommandInput, HistoryCell, HistoryCellType, Logo, Preferences, SelectedModel, Theme},
flows::{ExitFlow, Flow, FlowEvent, FlowRegistry, ModelRegistriesFlow, SettingsFlow, ThemeFlow},
helpers::SYMBOL_COMMAND,
+ keyboard_enhancement::KeyboardEnhancement,
sessions::{self, SessionState},
},
};
@@ -111,6 +112,7 @@ pub fn Application(
props: &ApplicationProps,
mut hooks: Hooks,
) -> impl Into<AnyElement<'static>> {
+ hooks.use_hook(KeyboardEnhancement::default);
let engine = props.engine.clone().expect("Application requires an engine");
let state = hooks.use_state(|| ApplicationState {
diff --git a/crates/legacy/cli/src/interactive/helpers/hint.rs b/crates/legacy/cli/src/interactive/helpers/hint.rs
index 61f063eba..823c302e4 100644
--- a/crates/legacy/cli/src/interactive/helpers/hint.rs
+++ b/crates/legacy/cli/src/interactive/helpers/hint.rs
@@ -1,5 +1,5 @@
pub const HINT_COMMANDS: &str = "/ for commands";
-pub const HINT_SEND: &str = "enter to send";
+pub const HINT_SEND: &str = "enter to send, shift+enter for a new line";
// An example input, line by line, with what it is and a note on how it's written.
pub struct HintExample {
pub label: &'static str,
@@ -13,7 +13,7 @@ pub const HINT_DECISION_STATE_EXAMPLES: &[HintExample] = &[HintExample {
lines: &["This LLM runs right on my laptop and answers in under a second, love it!"],
note: "a message, a document or JSON",
}];
-pub const HINT_DECISION_STATE_NOTES: &[&str] = &["ctrl+j, or \\ then enter, starts a new line"];
+pub const HINT_DECISION_STATE_NOTES: &[&str] = &["shift+enter for a new line (also ctrl+j or \\ then enter)"];
pub const HINT_DECISION_QUESTION_TITLE: &str =
"Ask a question about the text, then press enter. Each question is sent on its own";
pub const HINT_DECISION_QUESTION_EXAMPLES: &[HintExample] = &[
@@ -34,7 +34,7 @@ pub const HINT_DECISION_QUESTION_EXAMPLES: &[HintExample] = &[
},
];
pub const HINT_DECISION_QUESTION_NOTES: &[&str] =
- &["esc to change the text", "ctrl+j, or \\ then enter, starts a new line"];
+ &["esc to change the text", "shift+enter for a new line (also ctrl+j or \\ then enter)"];
pub const HINT_STORAGE_PAUSE_RESUME: &str = "ctrl+p to pause/resume download";
pub const HINT_STORAGE_DELETE: &str = "ctrl+d to delete model";
pub const HINT_SESSION_INTERRUPT: &str = "esc to interrupt";
diff --git a/crates/legacy/cli/src/interactive/keyboard_enhancement.rs b/crates/legacy/cli/src/interactive/keyboard_enhancement.rs
new file mode 100644
index 000000000..49f6d308c
--- /dev/null
+++ b/crates/legacy/cli/src/interactive/keyboard_enhancement.rs
@@ -0,0 +1,41 @@
+use std::io::{IsTerminal, stdout};
+
+use crossterm::{
+ event::{KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags},
+ execute,
+};
+use iocraft::{ComponentUpdater, Hook};
+
+#[derive(Default)]
+pub struct KeyboardEnhancement {
+ enabled: bool,
+}
+
+impl Hook for KeyboardEnhancement {
+ fn post_component_update(
+ &mut self,
+ updater: &mut ComponentUpdater,
+ ) {
+ if self.enabled || !stdout().is_terminal() || updater.terminal_events().is_none() {
+ return;
+ }
+
+ self.enabled = execute!(
+ stdout(),
+ PushKeyboardEnhancementFlags(
+ KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
+ | KeyboardEnhancementFlags::REPORT_EVENT_TYPES
+ | KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
+ )
+ )
+ .is_ok();
+ }
+}
+
+impl Drop for KeyboardEnhancement {
+ fn drop(&mut self) {
+ if self.enabled {
+ let _ = execute!(stdout(), PopKeyboardEnhancementFlags);
+ }
+ }
+}
diff --git a/crates/legacy/cli/src/interactive/mod.rs b/crates/legacy/cli/src/interactive/mod.rs
index b7cf64b6b..fb5f282b5 100644
--- a/crates/legacy/cli/src/interactive/mod.rs
+++ b/crates/legacy/cli/src/interactive/mod.rs
@@ -12,6 +12,7 @@ mod app;
mod components;
mod flows;
mod helpers;
+mod keyboard_enhancement;
mod list;
mod non_interactive;
mod sampling;