did some progress
This commit is contained in:
parent
9300750af1
commit
a1f49ee90e
10 changed files with 3938 additions and 2 deletions
19
.direnv/bin/nix-direnv-reload
Executable file
19
.direnv/bin/nix-direnv-reload
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
if [[ ! -d "/mnt/verbatim/projects/rust/file-explorer" ]]; then
|
||||
echo "Cannot find source directory; Did you move it?"
|
||||
echo "(Looking for "/mnt/verbatim/projects/rust/file-explorer")"
|
||||
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# rebuild the cache forcefully
|
||||
_nix_direnv_force_reload=1 direnv exec "/mnt/verbatim/projects/rust/file-explorer" true
|
||||
|
||||
# Update the mtime for .envrc.
|
||||
# This will cause direnv to reload again - but without re-building.
|
||||
touch "/mnt/verbatim/projects/rust/file-explorer/.envrc"
|
||||
|
||||
# Also update the timestamp of whatever profile_rc we have.
|
||||
# This makes sure that we know we are up to date.
|
||||
touch -r "/mnt/verbatim/projects/rust/file-explorer/.envrc" "/mnt/verbatim/projects/rust/file-explorer/.direnv"/*.rc
|
||||
1
.direnv/flake-inputs/dyaglk6gkk3nxvq7q6y3b5478iz3w6lh-source
Symbolic link
1
.direnv/flake-inputs/dyaglk6gkk3nxvq7q6y3b5478iz3w6lh-source
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
/nix/store/dyaglk6gkk3nxvq7q6y3b5478iz3w6lh-source
|
||||
1
.direnv/flake-inputs/k6xl9d1zp3sci53syp5rsa9q0xfh23c9-source
Symbolic link
1
.direnv/flake-inputs/k6xl9d1zp3sci53syp5rsa9q0xfh23c9-source
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
/nix/store/k6xl9d1zp3sci53syp5rsa9q0xfh23c9-source
|
||||
1
.direnv/flake-inputs/lv4kcr2y4b9k4ynhkga157507zxf372b-source
Symbolic link
1
.direnv/flake-inputs/lv4kcr2y4b9k4ynhkga157507zxf372b-source
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
/nix/store/lv4kcr2y4b9k4ynhkga157507zxf372b-source
|
||||
1
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa
Symbolic link
1
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
/nix/store/src81dqkfd9xdkwww4nyvnzbzyl75zra-nix-shell-env
|
||||
2176
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc
Normal file
2176
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc
Normal file
File diff suppressed because it is too large
Load diff
1520
Cargo.lock
generated
Normal file
1520
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -4,3 +4,5 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
crossterm = "0.29.0"
|
||||
ratatui = "0.30.0"
|
||||
|
|
|
|||
61
src/im_gonna_try_better.rs
Normal file
61
src/im_gonna_try_better.rs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
use std::{env, fs, path};
|
||||
|
||||
use crossterm::event::{self, Event, KeyCode};
|
||||
use ratatui::{
|
||||
style::{Color, Style, Stylize},
|
||||
widgets::{Block, Borders, List, ListState, Padding},
|
||||
};
|
||||
|
||||
fn list_dir(path: &str) -> Vec<String> {
|
||||
let paths = fs::read_dir(path).unwrap();
|
||||
let mut array_of_dirs: Vec<String> = Vec::new();
|
||||
|
||||
for path in paths {
|
||||
array_of_dirs.push(path.unwrap().path().display().to_string());
|
||||
}
|
||||
|
||||
array_of_dirs
|
||||
}
|
||||
|
||||
fn create_list<'a>(ls_result: Vec<String>) -> List<'a> {
|
||||
let block = Block::new()
|
||||
.borders(Borders::ALL)
|
||||
.padding(Padding::symmetric(1, 1))
|
||||
.fg(Color::Blue);
|
||||
|
||||
List::new(ls_result)
|
||||
.block(block)
|
||||
.highlight_style(Style::new().reversed())
|
||||
}
|
||||
|
||||
fn get_events(state: ListState) {
|
||||
match event::read().expect("failed to read event") {
|
||||
Event::Key(key_event) => match key_event.code {
|
||||
KeyCode::Esc => {
|
||||
break;
|
||||
}
|
||||
|
||||
KeyCode::Down => {
|
||||
state.select_next();
|
||||
}
|
||||
|
||||
KeyCode::Up => {
|
||||
state.select_previous();
|
||||
}
|
||||
|
||||
KeyCode::Left => (),
|
||||
|
||||
KeyCode::Right => (),
|
||||
|
||||
_ => (),
|
||||
},
|
||||
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut path = env::current_dir().unwrap();
|
||||
let mut terminal = ratatui::init();
|
||||
let mut state = ListState::default();
|
||||
}
|
||||
158
src/main.rs
158
src/main.rs
|
|
@ -1,3 +1,157 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::{env, fs, io, path::PathBuf};
|
||||
|
||||
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind};
|
||||
use ratatui::{
|
||||
DefaultTerminal, Frame,
|
||||
buffer::Buffer,
|
||||
layout::Rect,
|
||||
style::{Color, Stylize},
|
||||
widgets::{Block, Borders, List, ListState, Padding, StatefulWidget},
|
||||
};
|
||||
|
||||
struct App<'a> {
|
||||
window: Window<'a>,
|
||||
exit: bool,
|
||||
}
|
||||
|
||||
impl App<'_> {
|
||||
fn run(&mut self, terminal: &mut DefaultTerminal) -> io::Result<()> {
|
||||
while !self.exit {
|
||||
terminal.draw(|frame| self.draw(frame))?;
|
||||
self.handle_events()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn draw(&mut self, frame: &mut Frame) {
|
||||
self.window.render(frame.area(), frame.buffer_mut());
|
||||
}
|
||||
|
||||
fn handle_events(&mut self) -> io::Result<()> {
|
||||
match event::read()? {
|
||||
Event::Key(key_event) if key_event.kind == KeyEventKind::Press => {
|
||||
self.handle_key_events(key_event)
|
||||
}
|
||||
|
||||
_ => {}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_key_events(&mut self, key_event: KeyEvent) {
|
||||
match key_event.code {
|
||||
KeyCode::Char('q') | KeyCode::Esc => self.exit(),
|
||||
KeyCode::Down => self.window.state.select_next(),
|
||||
KeyCode::Up => self.window.state.select_previous(),
|
||||
KeyCode::Left => {
|
||||
self.window.absolute_path.pop();
|
||||
self.window.update();
|
||||
}
|
||||
KeyCode::Right => match self.window.state.selected() {
|
||||
Some(val) => {
|
||||
self.window
|
||||
.absolute_path
|
||||
.push(self.window.prepare_updated_list()[val].clone());
|
||||
self.window.update();
|
||||
}
|
||||
None => {
|
||||
print!("hello");
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn exit(&mut self) {
|
||||
self.exit = true;
|
||||
}
|
||||
}
|
||||
|
||||
struct Window<'a> {
|
||||
widget: WindowWidget<'a>,
|
||||
absolute_path: PathBuf,
|
||||
state: ListState,
|
||||
}
|
||||
|
||||
impl Window<'_> {
|
||||
fn new(absolute_path: PathBuf) -> Self {
|
||||
Window {
|
||||
widget: WindowWidget::new(Self::prepare_list(&absolute_path)),
|
||||
absolute_path,
|
||||
state: ListState::default().with_selected(Some(0)),
|
||||
}
|
||||
}
|
||||
|
||||
fn render(&mut self, area: Rect, buf: &mut Buffer) {
|
||||
self.widget.render(area, buf, &mut self.state);
|
||||
}
|
||||
|
||||
fn prepare_list(absolute_path: &PathBuf) -> Vec<String> {
|
||||
match fs::read_dir(absolute_path) {
|
||||
Ok(val) => {
|
||||
let mut the_list: Vec<String> = Vec::new();
|
||||
|
||||
for item in val {
|
||||
the_list.push(item.unwrap().path().display().to_string());
|
||||
}
|
||||
|
||||
return the_list;
|
||||
}
|
||||
Err(err) => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_updated_list(&self) -> Vec<String> {
|
||||
Self::prepare_list(&self.absolute_path)
|
||||
}
|
||||
|
||||
fn update(&mut self) {
|
||||
self.widget.update(self.prepare_updated_list());
|
||||
}
|
||||
}
|
||||
|
||||
struct WindowWidget<'a> {
|
||||
list: List<'a>,
|
||||
}
|
||||
|
||||
impl WindowWidget<'_> {
|
||||
fn update(&mut self, prepared_list: Vec<String>) {
|
||||
let block = Block::new()
|
||||
.borders(Borders::ALL)
|
||||
.padding(Padding::symmetric(1, 1))
|
||||
.fg(Color::Blue);
|
||||
|
||||
self.list = List::new(prepared_list)
|
||||
.block(block)
|
||||
.highlight_style(Color::Cyan);
|
||||
}
|
||||
|
||||
fn new(prepared_list: Vec<String>) -> Self {
|
||||
let mut window_widget = WindowWidget {
|
||||
list: List::new(Vec::<String>::new()),
|
||||
};
|
||||
|
||||
window_widget.update(prepared_list);
|
||||
window_widget
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulWidget for &mut WindowWidget<'_> {
|
||||
type State = ListState;
|
||||
|
||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut ListState) {
|
||||
StatefulWidget::render(&self.list, area, buf, state);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let mut terminal = ratatui::init();
|
||||
let dir = Window::new(env::current_dir().unwrap());
|
||||
let app_result = App {
|
||||
window: dir,
|
||||
exit: false,
|
||||
}
|
||||
.run(&mut terminal);
|
||||
ratatui::restore();
|
||||
app_result
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue