aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/input.rs42
-rw-r--r--src/ui.rs6
2 files changed, 16 insertions, 32 deletions
diff --git a/src/input.rs b/src/input.rs
index e87d46c..d7d891b 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -20,6 +20,7 @@ use url::Url;
use crate::command::Command;
+#[derive(PartialEq)]
pub enum Mode {
Normal,
Editing,
@@ -83,8 +84,6 @@ fn handle_normal_input(
) -> bool {
match key.code {
KeyCode::Char(':') => {
- app.input.push(':');
-
app.input_mode = Mode::Editing;
app.error = None;
}
@@ -153,24 +152,14 @@ fn handle_editing_input(
) -> bool {
match key.code {
KeyCode::Enter => {
- if let Some(command) = app.input.get(1..) {
- app.command_history.reverse();
- app.command_history.push(command.to_string());
- app.command_history.reverse();
- }
+ app.command_history.reverse();
+ app.command_history.push(app.input.to_string());
+ app.command_history.reverse();
- match Command::from(
- app.input.to_string().get(1..).unwrap_or("").to_string(),
- ) {
+ match Command::from(app.input.to_string()) {
Command::Quit => return true,
- Command::Open(to) => {
+ Command::Open(to) =>
if let Some(to) = to {
- // Remove colon
- app.input = app.input.chars().rev().collect();
-
- app.input.pop();
-
- app.input = app.input.chars().rev().collect();
app.set_url(
Url::parse(&if to.starts_with("gemini://") {
to
@@ -183,17 +172,10 @@ fn handle_editing_input(
app.make_request();
} else {
app.error = Some("No URL provided for open command".to_string());
- }
- }
- Command::Unknown =>
- if app.input == ":" {
- app.input_mode = Mode::Normal;
- } else {
- app.error = Some(format!(
- "\"{}\" is not a valid command",
- app.input.to_string().get(1..).unwrap_or("")
- ));
},
+ Command::Unknown => {
+ app.error = Some(format!("\"{}\" is not a valid command", app.input));
+ }
Command::Wrap(at, error) =>
if let Some(error) = error {
app.error = Some(error);
@@ -214,7 +196,7 @@ fn handle_editing_input(
KeyCode::Up => {
if let Some(command) = app.command_history.get(app.command_history_cursor)
{
- app.input = format!(":{}", command);
+ app.input = command.to_string();
if app.command_history_cursor + 1 < app.command_history.len() {
app.command_history_cursor += 1;
@@ -232,11 +214,11 @@ fn handle_editing_input(
if let Some(command) = app.command_history.get(app.command_history_cursor)
{
- app.input = format!(":{}", command);
+ app.input = command.to_string();
}
if dead_set {
- app.input = ":".to_string();
+ app.input.clear();
}
}
KeyCode::Backspace => {
diff --git a/src/ui.rs b/src/ui.rs
index b43a119..44c7a04 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -72,8 +72,10 @@ pub fn ui<B: tui::backend::Backend>(
Paragraph::new(&**error).style(Style::default().bg(Color::Red)),
chunks[2],
);
- } else if !app.input.is_empty() {
- f.render_widget(Paragraph::new(&*app.input), chunks[2]);
+ } else if !app.input.is_empty()
+ || app.input_mode == crate::input::Mode::Editing
+ {
+ f.render_widget(Paragraph::new(format!(":{}", app.input)), chunks[2]);
}
if app.accept_response_input {