Make the prompt not null

pull/475/head
Arijit Basu 2 years ago committed by Arijit Basu
parent d2390285fb
commit 5f598648a8

@ -281,7 +281,7 @@ YAML: `FollowSymlink`
Set the input prompt temporarily, until the input buffer is reset. Set the input prompt temporarily, until the input buffer is reset.
Type: { SetInputPrompt = nullable string } Type: { SetInputPrompt = string }
Example: Example:

@ -154,7 +154,7 @@ pub struct LuaContextLight {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InputBuffer { pub struct InputBuffer {
pub buffer: Option<Input>, pub buffer: Option<Input>,
pub prompt: Option<String>, pub prompt: String,
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@ -285,7 +285,7 @@ impl App {
let input = InputBuffer { let input = InputBuffer {
buffer: Default::default(), buffer: Default::default(),
prompt: config.general.prompt.format.clone(), prompt: config.general.prompt.format.clone().unwrap_or_default(),
}; };
let mut app = Self { let mut app = Self {
@ -808,7 +808,7 @@ impl App {
} }
} }
fn set_input_prompt(mut self, p: Option<String>) -> Result<Self> { fn set_input_prompt(mut self, p: String) -> Result<Self> {
self.input.prompt = p; self.input.prompt = p;
Ok(self) Ok(self)
} }
@ -883,7 +883,13 @@ impl App {
fn reset_input_buffer(mut self) -> Result<Self> { fn reset_input_buffer(mut self) -> Result<Self> {
self.input = InputBuffer { self.input = InputBuffer {
buffer: Default::default(), buffer: Default::default(),
prompt: self.config.general.prompt.format.clone(), prompt: self
.config
.general
.prompt
.format
.to_owned()
.unwrap_or_default(),
}; };
Ok(self) Ok(self)
} }

@ -242,13 +242,13 @@ pub enum ExternalMsg {
/// Set the input prompt temporarily, until the input buffer is reset. /// Set the input prompt temporarily, until the input buffer is reset.
/// ///
/// Type: { SetInputPrompt = nullable string } /// Type: { SetInputPrompt = string }
/// ///
/// Example: /// Example:
/// ///
/// - Lua: `{ SetInputPrompt = "→" }` /// - Lua: `{ SetInputPrompt = "→" }`
/// - YAML: `SetInputPrompt: →` /// - YAML: `SetInputPrompt: →`
SetInputPrompt(Option<String>), SetInputPrompt(String),
/// Update the input buffer using cursor based operations. /// Update the input buffer using cursor based operations.
/// ///

@ -817,12 +817,7 @@ fn draw_input_buffer<B: Backend>(
1 1
} else { } else {
0 0
} + app } + app.input.prompt.chars().count() as u16;
.input
.prompt
.as_ref()
.map(|t| t.chars().count() as u16)
.unwrap_or(0);
let cursor_offset_right = if config let cursor_offset_right = if config
.borders .borders
@ -841,7 +836,7 @@ fn draw_input_buffer<B: Backend>(
let input_buf = Paragraph::new(Spans::from(vec![ let input_buf = Paragraph::new(Spans::from(vec![
Span::styled( Span::styled(
app.input.prompt.to_owned().unwrap_or_default(), app.input.prompt.to_owned(),
app.config.general.prompt.style.to_owned().into(), app.config.general.prompt.style.to_owned().into(),
), ),
Span::raw(input.value()), Span::raw(input.value()),

Loading…
Cancel
Save