Skip to content

Commit f4e43cb

Browse files
committed
Removed rustyline and readline interface, added TUI
1 parent 4a35dbc commit f4e43cb

File tree

2 files changed

+46
-119
lines changed

2 files changed

+46
-119
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ authors = ["Cory Driscoll <[email protected]>"]
88
[dependencies]
99
mammut = "0.12.0"
1010
toml = "0.4.6"
11-
rustyline = "2.0.1"
1211
cursive = "0.12"
1312
kuchiki = "0.7.3"
1413
webbrowser = "0.2.2"

src/main.rs

+46-118
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ mod register;
33
extern crate cursive;
44
extern crate kuchiki;
55
extern crate mammut;
6-
extern crate rustyline;
76
extern crate toml;
87

98
use cursive::align::HAlign;
109
use cursive::theme::{BaseColor, BorderStyle, Color, ColorStyle, PaletteColor, Theme};
1110
use cursive::traits::*;
11+
use cursive::utils::markup::StyledString;
1212
use cursive::views::{
13-
Dialog, DummyView, EditView, LinearLayout, ListView, SelectView, TextArea, TextView,
13+
BoxView, Dialog, DummyView, EditView, LinearLayout, ListView, SelectView, TextArea, TextView,
1414
};
1515
use cursive::Cursive;
1616

@@ -19,40 +19,11 @@ use kuchiki::traits::TendrilSink;
1919
use mammut::entities::status::Status;
2020
use mammut::status_builder::{StatusBuilder, Visibility::*};
2121
use mammut::Mastodon;
22-
use rustyline::{error::ReadlineError, Editor};
2322

2423
fn main() {
2524
interface();
2625
}
2726

28-
fn terminal() {
29-
let mut rl = Editor::<()>::new();
30-
loop {
31-
let input = rl.readline("[Procul]>> ");
32-
match input {
33-
Ok(line) => match line.as_ref() {
34-
"q" | "quit" => {
35-
println!("Quitting Procul");
36-
std::process::exit(0);
37-
}
38-
"n" => {
39-
println!("Entering Post Mode");
40-
new_status();
41-
}
42-
"tl" => {
43-
println!("Fetching timeline posts...");
44-
let _mastodon = register::get_mastodon_data().unwrap();
45-
view_home_tl(_mastodon.clone());
46-
}
47-
_ => println!("Invalid input"),
48-
},
49-
Err(_err) => {
50-
println!("Unknown Error");
51-
}
52-
}
53-
}
54-
}
55-
5627
#[allow(dead_code)]
5728
pub fn interface() {
5829
let mut siv = Cursive::default();
@@ -84,36 +55,59 @@ pub fn interface() {
8455
.child(TextView::new("").h_align(HAlign::Right).fixed_width(30)),
8556
)
8657
.child(
87-
Dialog::new()
88-
.title("New Post")
89-
.padding((1, 1, 1, 0))
90-
.content(
91-
TextArea::new()
92-
.with_id("post")
93-
.fixed_width(20)
94-
.fixed_height(5),
95-
)
96-
.button("Post", move |s| {
97-
s.call_on_id("post", |view: &mut EditView| {
98-
_mastodon.new_status(StatusBuilder {
99-
status: view.get_content().to_string(),
100-
in_reply_to_id: None,
101-
media_ids: None,
102-
sensitive: Some(false),
103-
spoiler_text: None,
104-
visibility: Some(Public),
58+
LinearLayout::horizontal().child(
59+
Dialog::new()
60+
.title("New Post")
61+
.padding((1, 1, 1, 0))
62+
.content(
63+
TextArea::new()
64+
.with_id("post")
65+
.fixed_width(20)
66+
.fixed_height(5),
67+
)
68+
.button("Post", |s| {
69+
s.call_on_id("post", |view: &mut TextArea| {
70+
post_status(&view.get_content().to_string());
71+
view.set_content("");
10572
});
106-
});
107-
}),
73+
}),
74+
),
10875
)
109-
.child(DummyView.fixed_height(1)),
76+
.child(DummyView.fixed_height(1))
77+
.child(BoxView::with_full_width(SelectView::new().with(|list| {
78+
//let timeline = _mastodon.get_home_timeline();
79+
let _mastodon = register::get_mastodon_data().unwrap();
80+
let resp = _mastodon.get_home_timeline().unwrap();
81+
for status in resp.initial_items {
82+
let parser = kuchiki::parse_html();
83+
let node_ref = parser.one(&status.content[..]);
84+
let text = node_ref.text_contents();
85+
let account_name = status.account.acct;
86+
let status_string = format!("@{}: {}", account_name, &text);
87+
let status_id = status.id;
88+
list.add_item(status_string, status_id);
89+
//println!("@{}: {}", account_name, &text);
90+
}
91+
}))),
11092
)
11193
.h_align(HAlign::Center),
11294
);
11395

11496
siv.run();
11597
}
11698

99+
fn post_status(text: &str) {
100+
let _mastodon = register::get_mastodon_data().unwrap();
101+
_mastodon.new_status(StatusBuilder {
102+
status: text.to_string(),
103+
in_reply_to_id: None,
104+
media_ids: None,
105+
sensitive: Some(false),
106+
spoiler_text: None,
107+
visibility: Some(Public),
108+
});
109+
}
110+
117111
fn theme_terminal(siv: &Cursive) -> Theme {
118112
let mut theme = siv.current_theme().clone();
119113
theme.palette[PaletteColor::Background] = Color::TerminalDefault;
@@ -157,69 +151,3 @@ fn view_home_tl(client: Mastodon) {
157151
};
158152
display_timeline(&timeline.initial_items);
159153
}
160-
161-
#[allow(dead_code)]
162-
fn unlisted_post() {
163-
let mut rl = Editor::<()>::new();
164-
let _mastodon = register::get_mastodon_data().unwrap();
165-
166-
loop {
167-
let input = rl.readline("[Unlisted]>> ");
168-
match input {
169-
Ok(line) => {
170-
_mastodon
171-
.new_status(StatusBuilder {
172-
status: String::from(line),
173-
in_reply_to_id: None,
174-
media_ids: None,
175-
sensitive: Some(false),
176-
spoiler_text: None,
177-
visibility: Some(Unlisted),
178-
})
179-
.expect("Couldn't post status");
180-
println!("Status Posted!");
181-
terminal();
182-
}
183-
Err(ReadlineError::Interrupted) => {
184-
println!("CTRL+C");
185-
std::process::exit(1);
186-
}
187-
Err(_err) => {
188-
println!("No input");
189-
}
190-
}
191-
}
192-
}
193-
194-
fn new_status() {
195-
let mut rl = Editor::<()>::new();
196-
let _mastodon = register::get_mastodon_data().unwrap();
197-
198-
loop {
199-
let input = rl.readline("[New Status]>> ");
200-
match input {
201-
Ok(line) => match line.as_ref() {
202-
":exit" => {
203-
println!("Returning to terminal...");
204-
terminal();
205-
}
206-
":public" => {
207-
//public_post();
208-
}
209-
":unlisted" => {
210-
unlisted_post();
211-
}
212-
_ => {
213-
println!("Options: ':public', ':unlisted'");
214-
}
215-
},
216-
Err(ReadlineError::Interrupted) => {
217-
println!("CTRL+C");
218-
std::process::exit(1);
219-
}
220-
Err(_err) => {
221-
println!("No input");
222-
}
223-
}
224-
}
225-
}

0 commit comments

Comments
 (0)