Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Deezzir committed Jan 14, 2023
0 parents commit 566bd0d
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .gitignore
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
8 changes: 8 additions & 0 deletions Cargo.toml
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"
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Todo

A terminal based todo list manager written in Rust.
74 changes: 74 additions & 0 deletions src/main.rs
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),
_ => {}
}
}
}
}
49 changes: 49 additions & 0 deletions src/main.txt
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();
}
3 changes: 3 additions & 0 deletions src/todo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod style;

pub use self::style::*;

0 comments on commit 566bd0d

Please sign in to comment.