-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 566bd0d
Showing
6 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/rust | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=rust | ||
|
||
### Rust ### | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/rust | ||
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode | ||
|
||
### VisualStudioCode ### | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
!.vscode/*.code-snippets | ||
|
||
# Local History for Visual Studio Code | ||
.history/ | ||
|
||
# Built Visual Studio Code Extensions | ||
*.vsix | ||
|
||
### VisualStudioCode Patch ### | ||
# Ignore all local history of files | ||
.history | ||
.ionide | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode | ||
|
||
|
||
# Added by cargo | ||
|
||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "todo" | ||
author = ["Iurii Kondrakov <[email protected]>"] | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
termion = "2.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Todo | ||
|
||
A terminal based todo list manager written in Rust. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
extern crate termion; | ||
|
||
use std::cmp::*; | ||
use std::io::{stdin, stdout, Read, Write}; | ||
use termion::event::Key; | ||
use termion::input::TermRead; | ||
use termion::raw::{IntoRawMode}; | ||
use termion::screen::{IntoAlternateScreen, AlternateScreen}; | ||
use termion::{color, style}; | ||
|
||
fn screen_highlight<W: Write>(s: &mut AlternateScreen<W>) { | ||
write!( | ||
s, | ||
"{}{}", | ||
color::Fg(color::Black), | ||
color::Bg(color::White) | ||
).unwrap(); | ||
} | ||
|
||
fn screen_write<W: Write>(s: &mut AlternateScreen<W>, text: &str, row: u16) { | ||
write!(s, "{}{}", termion::cursor::Goto(1, (row + 1) as u16), text).unwrap(); | ||
} | ||
|
||
fn screen_style_reset<W: Write>(s: &mut AlternateScreen<W>) { | ||
write!(s, "{}", style::Reset).unwrap(); | ||
} | ||
|
||
fn main() { | ||
let mut stdin = stdin(); | ||
let mut screen = stdout() | ||
.into_raw_mode() | ||
.unwrap() | ||
.into_alternate_screen() | ||
.unwrap(); | ||
|
||
write!( | ||
screen, | ||
"{}{}", | ||
termion::clear::All, | ||
termion::cursor::Goto(1, 1) | ||
) | ||
.unwrap(); | ||
screen.flush().unwrap(); | ||
|
||
let mut cur_todo: usize = 0; | ||
let mut quit: bool = false; | ||
let todos: Vec<&str> = vec![ | ||
"Finish Scancore", | ||
"Make a cup of tea", | ||
"Write a Rust TODO app", | ||
]; | ||
|
||
while !quit { | ||
for (row, todo) in todos.iter().enumerate() { | ||
if cur_todo == row { screen_highlight(&mut screen); } | ||
screen_write(&mut screen, todo, row as u16); | ||
screen_style_reset(&mut screen); | ||
} | ||
screen.flush().unwrap(); | ||
|
||
if let Some(Ok(key)) = stdin.by_ref().keys().next() { | ||
match key { | ||
Key::Esc | Key::Char('q') => quit = true, | ||
Key::Up | Key::Char('w') => { | ||
if cur_todo > 0 { | ||
cur_todo -= 1; | ||
} | ||
} | ||
Key::Down | Key::Char('s') => cur_todo = min(cur_todo + 1, todos.len() - 1), | ||
_ => {} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
mod todo; | ||
|
||
use todo::*; | ||
use std::vec; | ||
use ncurses::*; | ||
use std::cmp::*; | ||
|
||
fn main() { | ||
initscr(); | ||
init_style(); | ||
|
||
let mut quit: bool = false; | ||
let mut cur_todo: usize = 0; | ||
let mut todos: Vec<&str> = vec![ | ||
"Finish Scancore", | ||
"Make a cup of tea", | ||
"Write a Rust TODO app" | ||
]; | ||
|
||
while !quit { | ||
for (row, todo) in todos.iter().enumerate() { | ||
let pair = { | ||
if row == cur_todo { | ||
HIGHLIGHT_PAIR | ||
} else { | ||
REGULAR_PAIR | ||
} | ||
}; | ||
|
||
attron(COLOR_PAIR(pair)); | ||
mv(row as i32, 1); | ||
addstr(*todo); | ||
attroff(COLOR_PAIR(pair)); | ||
} | ||
|
||
refresh(); | ||
|
||
let key: i32 = getch(); | ||
match key as u8 as char { | ||
'q'|'Q'| => quit = true, | ||
'w'|'W' => if cur_todo > 0 { | ||
cur_todo -= 1; | ||
}, | ||
's'|'S' => cur_todo = min(cur_todo + 1, todos.len()), | ||
_ => {} | ||
} | ||
} | ||
endwin(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod style; | ||
|
||
pub use self::style::*; |