TUI client in progress now, for now its just being wireframed

This commit is contained in:
shockrah 2021-01-17 02:40:22 -08:00
parent 60aee1dc07
commit 963d29801d
7 changed files with 1721 additions and 0 deletions

1
tui/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target/

1572
tui/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

23
tui/Cargo.toml Normal file
View File

@ -0,0 +1,23 @@
[package]
name = "tui"
version = "0.1.0"
authors = ["shockrah <alejandros714@protonmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = "2.33.3"
cursive = "0.15"
serde_json = "1.0"
serde = { version = "1.0.114", features = ["derive"] }
reqwest = "0.11.0"
tokio = { version = "1", features = ["full"] }
[patch.crates-io.enumset_derive]
git = "https://github.com/ocboogie/enumset"
branch = "span-fix"

6
tui/src/auth.rs Normal file
View File

@ -0,0 +1,6 @@
// Deals with logging in and requesting new jwt's when required
async fn login() {}
async fn refresh_jwt() {}

14
tui/src/http.rs Normal file
View File

@ -0,0 +1,14 @@
use reqwest;
use crate::types::Channel;
pub async fn fetch_channels(domain: &str) -> Option<Vec<Channel>>{
if let Ok(resp) = reqwest::get(format!("{}/channels/list", domain)).await {
let bytes = resp.bytes().await.unwrap();
let res: Result<Vec<Channel>, serde_json::Error> = serde_json::from_slice(&bytes);
return match res {
Ok(res) => Some(res),
_ => None
};
}
return None;
}

81
tui/src/main.rs Normal file
View File

@ -0,0 +1,81 @@
extern crate serde;
extern crate clap;
extern crate cursive;
extern crate tokio;
extern crate reqwest;
use std::{fs, env};
use clap::{Arg, App};
use cursive::views::{CircularFocus, Dialog, TextView};
use cursive::Cursive;
use cursive::event::Key;
use serde_json;
mod types;
mod http;
#[tokio::main]
async fn main() {
let args = App::new("Freechat TUI")
.version("69.420")
.author("godrah")
.about("oh you know")
.arg(Arg::with_name("config")
.short("c")
.long("config")
.value_name("CONFIG")
.help("Specify path of config to use")
.takes_value(true)).get_matches();
let config: types::Config = if args.args.len() == 0 {
let home = env::var("HOME").unwrap();
match fs::read_to_string(format!("{}/.config/freechat/config.json", home)) {
Ok(data) => serde_json::from_str(&data).unwrap(),
Err(e) => panic!("Bro: {}", e)
}
} else{
let path = args.value_of("config").unwrap();
match fs::read_to_string(path) {
Ok(data) => serde_json::from_str(&data).unwrap(),
Err(e) => panic!("Bro: {}", e)
}
};
let mut app = cursive::default();
app.add_global_callback('q', Cursive::quit);
app.add_global_callback(Key::Esc, |s| s.select_menubar());
app.add_layer(CircularFocus::wrap_tab(
Dialog::around(TextView::new("something"))
.title("Freechat")
.button("Random", |_s| {})
.button("Quit", |s| { s.quit() })
));
// menu bar at the top lets us pick between different servers in the config
for server in config.servers.iter() {
let name = match &server.name {
Some(name) => name.to_string(),
None => String::from("None")
};
match http::fetch_channels(&server.ip).await {
Some(channels) => {
// add the channels to the current sub tree
for channel in channels {
app.menubar().add_leaf(name, |_| {});
}
},
_ => {}
}
app.menubar().add_leaf(name, |_| {/* */});
}
app.run();
}

24
tui/src/types.rs Normal file
View File

@ -0,0 +1,24 @@
use serde::{Serialize,Deserialize};
#[derive(Deserialize, Serialize)]
pub struct Server {
pub name: Option<String>,
pub domain: Option<String>,
pub ip: String,
pub description: Option<String>,
pub key: String, // the secret hush hush uwu
pub id: u64,
pub nickname: Option<String>
}
#[derive(Deserialize, Serialize)]
pub struct Config {
pub username: String, // global username that is only overriden in server context's if nickname is used
pub servers: Vec<Server>
}
#[derive(Deserialize)]
pub struct Channel {
pub ip: String,
pub name: String,
}