Comments (12)
Hi, thanks for chiming in,
1- The current implementation is just a placeholder till a correct one lands (actually print the multi-lines input in a multi-lines way), I just added this basic implementation to unbreak it, at least now its possible to paste multi-lines
2- good idea I'll add your suggestions
from irust.
from irust.
Would you check out 9559a27
Its the easiest way to implement multilines handling but its a bit of cheating so I want to know how do you see this in practice
from irust.
Would you check out 9559a27
It does not print output now :D
I think that in case of .
, :
and =
at the end of the line, Enter should enter new line, not run command (if StringTools::unmatched_brackets(&self.buffer) {
-> if self.incomplete_input() {
).
The spaces are bit annoying to delete. If irust stored positions of first and last FakeSpaces and was changing behavior of keys, it could fool anyone. But that seems like quite a lot of work.
An alternative would be to implement buffer
"properly", that is separate UI and logic layers. Example:
struct IRust {
buffer: Buffer,
buffer_pos: u64,
cursor_pos: (u64, u64),
// ...
}
struct Buffer {
elements: Vec<BufferElement>,
starting_coords: (u64, u64),
}
enum BufferElement {
UserInput(char),
NewLine,
SuggestionCharacter(char),
// ...
}
impl Buffer {
fn print(&self) {
cursor.goto(self.starting_coords.0, self.starting_coords.1);
let mut current_x = self.starting_coords.0;
for element in self.elements {
match element {
UserInput(_) => set_color(White);
SuggestionCharacter(_) => set_color(Red);
...
}
let text_to_print = element_to_string(element, current_x);
current_x += text_to_print;
print(text_to_print);
}
}
fn len(&self) -> u64 {
let mut len = self.starting_coords.0;
for element in self.elements {
let text = element_to_string(element, current_x);
len += text;
}
len - self.starting_coords.0
}
fn hide(&self) {
cursor.goto(self.starting_coords.0, self.starting_coords.1);
for _ in 0..self.len() {
print(' ');
}
}
}
fn element_to_string(element: BufferElement, current_x: u64) -> String {
match element {
UserInput(c) => c.to_string(),
SuggestionCharacter(c) => c.to_string(),
NewLine => {
// do the math using current_x and return enough spaces
},
}
}
fn handle_left_arrow() {
self.buffer_pos = self.buffer_pos.saturating_sub(1);
self.cursor_pos = self.buffer.buffer_pos_to_cursor_pos(buffer_pos);
move_cursor(self.cursor_pos);
}
fn handle_backspace() {
if self.buffer_pos > 0 {
self.buffer.hide(); // hide buffer before manipulating it
self.buffer.elements.remove(self.buffer_pos);
self.buffer_pos -= 1;
self.buffer.print();
self.cursor_pos = self.buffer.buffer_pos_to_cursor_pos(buffer_pos);
move_cursor(self.cursor_pos);
}
}
However, this is also quite a lot of work. I don't mind if the current code stays for now (just fix the no-output bug), and an issue may be kept opened as a reminder to fix it one day if IRust ever gets popular.
from irust.
this should fix that bug 5424774 btw you can jump the spaces with ctrl,
I defenitly hear you currently this feels like a bunch of hacks glued together, I just want to add features the fastest way possible, but I'm planning to stop at some point and refactor the code and then implement the buffer properly as you suggested
from irust.
I like the code snippet btw, that would be a very nice rework
from irust.
@pzmarzly here is the new rework https://github.com/sigmaSd/IRust/tree/cursor_rework
I would appreciate if you test it, it really needs a lot of feedback
from irust.
Open IRust, hit a
, hit Delete
(at end of the line):
thread 'main' panicked at 'assertion failed: index < len', src/liballoc/vec.rs:918:9
stack backtrace:
0: 0x5622f7d40a43 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::had1ef077bf7ec324
at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
1: 0x5622f7d3befb - std::sys_common::backtrace::_print::h6f882ddc0cb23bba
at src/libstd/sys_common/backtrace.rs:71
2: 0x5622f7d3f7b6 - std::panicking::default_hook::{{closure}}::h47bab10d9b5498ff
at src/libstd/sys_common/backtrace.rs:59
at src/libstd/panicking.rs:197
3: 0x5622f7d3f549 - std::panicking::default_hook::h53275efa9b0ada2b
at src/libstd/panicking.rs:211
4: 0x5622f7d3febf - std::panicking::rust_panic_with_hook::h34d4d9732505a471
at src/libstd/panicking.rs:474
5: 0x5622f7d3fa41 - std::panicking::continue_panic_fmt::h65d9e3a7af1dc8c7
at src/libstd/panicking.rs:381
6: 0x5622f7d3f925 - rust_begin_unwind
at src/libstd/panicking.rs:308
7: 0x5622f7d5a4ac - core::panicking::panic_fmt::hf3b57135fadc0b38
at src/libcore/panicking.rs:85
8: 0x5622f7d5a3eb - core::panicking::panic::ha0ca1c9d1c3544ee
at src/libcore/panicking.rs:49
9: 0x5622f7afa066 - alloc::vec::Vec<T>::remove::h650f186bb674a627
at /home/pzmarzly/proj/IRust/<::core::macros::panic macros>:3
10: 0x5622f7a9ab71 - irust::utils::StringTools::remove_at_char_idx::h63cc30ea13b6dbd9
at src/utils.rs:56
11: 0x5622f7ace707 - irust::irust::writer::<impl irust::irust::IRust>::delete_char::h19a22e22b250a91b
at src/irust/writer.rs:93
12: 0x5622f7ac10fa - irust::irust::events::<impl irust::irust::IRust>::handle_del::hf10aa28111632645
at src/irust/events.rs:207
13: 0x5622f7acfabb - irust::irust::IRust::run::h589f0e35e7a53163
at src/irust.rs:155
14: 0x5622f7a9d787 - irust::main::hb73c685754312ccc
at src/main.rs:19
15: 0x5622f7af671f - std::rt::lang_start::{{closure}}::ha35049f235ae349d
at /rustc/af98304b9a006e2f9a367b1f79dd7655f243c150/src/libstd/rt.rs:64
16: 0x5622f7d3f8c2 - std::panicking::try::do_call::hbe3de9b60b83c31b
at src/libstd/rt.rs:49
at src/libstd/panicking.rs:293
17: 0x5622f7d47859 - __rust_maybe_catch_panic
at src/libpanic_unwind/lib.rs:85
18: 0x5622f7d403cc - std::rt::lang_start_internal::hefe5775a75294ddc
at src/libstd/panicking.rs:272
at src/libstd/panic.rs:388
at src/libstd/rt.rs:48
19: 0x5622f7af66f8 - std::rt::lang_start::hc95bc5844bece5c7
at /rustc/af98304b9a006e2f9a367b1f79dd7655f243c150/src/libstd/rt.rs:64
20: 0x5622f7a9d809 - main
21: 0x7ff6f0e72ce2 - __libc_start_main
22: 0x5622f7a9a19d - _start
23:0x0 - <unknown>
from irust.
I can't see any other problems (aside of my_rust_binary.log
and Home/End disabled)
from irust.
7f72f69
thanks a lot for testing so fast!
I'm going to make log a dev dependency, it was really useful for debugging (was having a hard time before without it)
from irust.
from irust.
I guess this can be closed, if you encounter some edge cases you can open specific bug report, thanks for the testing and feedback!
from irust.
Related Issues (20)
- Use `rustyline` or `reedline` for input? HOT 1
- Move theme settings from config.toml to themes config
- Improve Jupyter kernel support HOT 7
- typing twice in windows with crossterm-0.26+ HOT 2
- Can irust repl evaluate code with release mode instead of debug mode? HOT 3
- Cannot use two `irust_repl`s at the same time. HOT 27
- Rust analyzer is not working on Windows HOT 6
- Interactive usage HOT 3
- IRust installation fails due to use of unstable library feature 'once_cell' HOT 3
- FileNotFoundError while `python -m irust_kernel.install` HOT 1
- cargo-edit requires --path argument for a local dependency after version 0.9.1 HOT 2
- irust doesn't display Thai text properly. HOT 1
- Unclear documentation on importing local crates HOT 5
- Autocomplete doesn't work HOT 10
- untitled issue HOT 4
- Proposal: Split eval output HOT 3
- Option to specify config.toml path HOT 6
- Support nREPL protocol? HOT 2
- Failed to format error output HOT 2
- Logo missing on Jupyter lab launcher page HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from irust.