Skip to content
Merged

Misc #571

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion BUGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ Currently, performance is poor because, most of the time, we refresh the whole l
We would like to transform events on prompt/line/hint into partial repaint.

See `termwiz` design (`Surface`).
See `replxx` refresh delay (`_lastRefreshTime`)
See `replxx` refresh delay (`_lastRefreshTime`) or `python-prompt-toolkit` max_render_postpone_time.
https://docs.rs/xi-unicode/0.3.0/xi_unicode/struct.LineBreakIterator.html
https://github.com/xi-editor/xi-editor/blob/master/rust/core-lib/src/linewrap.rs
[vt100](https://docs.rs/vt100/0.12.0/vt100/struct.Screen.html#method.contents_diff)

## Action / Command

Expand Down
5 changes: 4 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
- if path used to save history is the same:
+ if timestamp is still the same => we can append only new lines if history has not been truncated.

```
HistoryInfo
first_add_index: Option<usize>, // first line inserted by this session
truncated: bool //
path_info: Option<PathInfo>,

```
```
PathInfo
path: Path,
modified: SystemTime,
```

---
With `termwiz`, you can define your own `History` backend.
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ History
each line input session.
- [X] append_history
- [ ] history_truncate_file
- [ ] custom persistent storage

Input
- [ ] Password input (#58) (https://github.com/conradkdotcom/rpassword) (https://github.com/antirez/linenoise/issues/125)
Expand Down
12 changes: 6 additions & 6 deletions src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ use crate::line_buffer::LineBuffer;
use crate::{Context, Result};
use memchr::memchr;

// TODO: let the implementers choose/find word boundaries ???
// (line, pos) is like (rl_line_buffer, rl_point) to make contextual completion
// ("select t.na| from tbl as t")
// TODO: make &self &mut self ???

/// A completion candidate.
pub trait Candidate {
/// Text to display when listing alternatives.
Expand Down Expand Up @@ -69,18 +64,23 @@ impl Candidate for Pair {
}
}

// TODO: let the implementers customize how the candidate(s) are displayed
// https://github.com/kkawakam/rustyline/issues/302

/// To be called for tab-completion.
pub trait Completer {
/// Specific completion candidate.
type Candidate: Candidate;

// TODO: let the implementers choose/find word boundaries ??? => Lexer

/// Takes the currently edited `line` with the cursor `pos`ition and
/// returns the start position and the completion candidates for the
/// partial word to be completed.
///
/// ("ls /usr/loc", 11) => Ok((3, vec!["/usr/local/"]))
fn complete(
&self,
&self, // FIXME should be `&mut self`
line: &str,
pos: usize,
ctx: &Context<'_>,
Expand Down
4 changes: 3 additions & 1 deletion src/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub trait Highlighter {
/// Currently, used only with `CompletionType::List`.
fn highlight_candidate<'c>(
&self,
candidate: &'c str,
candidate: &'c str, // FIXME should be Completer::Candidate
completion: CompletionType,
) -> Cow<'c, str> {
let _ = completion;
Expand Down Expand Up @@ -94,6 +94,8 @@ impl<'r, H: ?Sized + Highlighter> Highlighter for &'r H {
const OPENS: &[u8; 3] = b"{[(";
const CLOSES: &[u8; 3] = b"}])";

/// TODO versus https://python-prompt-toolkit.readthedocs.io/en/master/pages/reference.html?highlight=HighlightMatchingBracketProcessor#prompt_toolkit.layout.processors.HighlightMatchingBracketProcessor

/// Highlight matching bracket when typed or cursor moved on.
#[derive(Default)]
pub struct MatchingBracketHighlighter {
Expand Down
6 changes: 6 additions & 0 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ pub struct SearchResult<'a> {
pub pos: usize,
}

/// HistoryEntry: text + timestamp
/// TODO Make possible to customize how history is stored / loaded.
/// https://github.com/kkawakam/rustyline/issues/442
/// https://github.com/kkawakam/rustyline/issues/127
/// See https://python-prompt-toolkit.readthedocs.io/en/master/pages/reference.html#prompt_toolkit.history.History abstract methods

/// Current state of the history.
#[derive(Default)]
pub struct History {
Expand Down
8 changes: 4 additions & 4 deletions src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ pub enum Cmd {
EndOfFile,
/// end-of-history
EndOfHistory,
/// forward-search-history
/// forward-search-history (incremental search)
ForwardSearchHistory,
/// history-search-backward
/// history-search-backward (common prefix search)
HistorySearchBackward,
/// history-search-forward
/// history-search-forward (common prefix search)
HistorySearchForward,
/// Indent current line
Indent(Movement),
Expand Down Expand Up @@ -79,7 +79,7 @@ pub enum Cmd {
ReplaceChar(RepeatCount, char),
/// vi-change-to, vi-substitute
Replace(Movement, Option<String>),
/// reverse-search-history
/// reverse-search-history (incremental search)
ReverseSearchHistory,
/// self-insert
SelfInsert(RepeatCount, char),
Expand Down
2 changes: 2 additions & 0 deletions src/line_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub(crate) trait ChangeListener: DeleteListener {
fn replace(&mut self, idx: usize, old: &str, new: &str);
}

// TODO split / cache lines ?

/// Represent the current input (text and cursor position).
///
/// The methods do text manipulations or/and cursor movements.
Expand Down
2 changes: 1 addition & 1 deletion src/tty/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ impl Renderer for PosixRenderer {
}
let col = read_digits_until(rdr, 'R')?;
debug!(target: "rustyline", "initial cursor location: {:?}", col);
if col.is_some() && col != Some(1) {
if col != Some(1) {
self.write_and_flush(b"\n")?;
}
Ok(())
Expand Down