Skip to content

Commit

Permalink
first tag
Browse files Browse the repository at this point in the history
  • Loading branch information
cht committed Dec 8, 2021
1 parent 2fdfd96 commit 650179f
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 91 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,28 @@

### v2ray tui 界面,静态编译

TODO
tui界面的v2ray

按键

* h
* 按h出设置界面,设置界面里面有两个设置
* v2raycore
* 订阅,当在第二个设置里面添加了订阅后按下键可以选中订阅,d键删除
* e
* TODO, 计划作为设置
* s
* 进入选择节点界面
* 此界面按F5可以运行core,ese+q退出后设置代理可以访问互联网
* 此界面左右键可以切换订阅
* ese + q
* 此两键各种退出

使用

```sh
export http_proxy=http://127.0.0.1:8889
export https_proxy=http://127.0.0.1:8889
```

然后可以联网
18 changes: 14 additions & 4 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::io;
use std::io::Stdout;
use tui::backend::CrosstermBackend;
use tui::Terminal;
use tui::widgets::ListState;
#[derive(Clone, Copy)]
pub enum Page {
SubScribe = 0,
Expand All @@ -25,13 +26,22 @@ pub fn run_app(terminal: &mut Terminal<MyBackend>) -> io::Result<()> {
let mut appsub = AppSub::default();
let informations = utils::start();
if !informations.is_empty() {
appsub.subs[0] = informations
//appsub.subs[0] = informations[0]
// .iter()
// .map(|amessage| spider::remove_quotation(amessage.ps.clone()))
// .collect();
appsub.subs = informations
.iter()
.map(|amessage| spider::remove_quotation(amessage.ps.clone()))
.map(|ainformation| ainformation
.iter()
.map(|message| spider::remove_quotation(message.ps.clone()))
.collect())
.collect();
appsub.stateoflist = true;
appsub.state[0].select(Some(0));
appsub.informations[0] = informations;
let len = informations.len();
appsub.state = vec![ListState::default();len];
//appsub.state[0].select(Some(0));
appsub.informations = informations.clone();
}
appsub.subscription = utils::get_subs();
appsub.settings_input[0] = utils::start_v2core();
Expand Down
15 changes: 14 additions & 1 deletion src/subscribe/appsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,20 @@ impl AppSub {
};
self.state[self.subsindex].select(Some(i));
}

pub fn left(&mut self){
if self.subsindex == 0 {
self.subsindex = self.state.len()-1;
} else {
self.subsindex -=1;
}
}
pub fn right(&mut self){
if self.subsindex >= self.state.len() -1 {
self.subsindex = 0;
} else {
self.subsindex +=1;
}
}
pub fn unselect(&mut self) {
self.state[self.subsindex].select(None);
}
Expand Down
12 changes: 5 additions & 7 deletions src/subscribe/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
InputMode::Editing => Style::default().fg(Color::Yellow),
_ => Style::default(),
})
.block(Block::default().borders(Borders::ALL).title("Input"));
.block(Block::default().borders(Borders::ALL).title("Search bar"));
f.render_widget(input, chunks[1]);
if let InputMode::Editing = app.input_mode {
// Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
Expand All @@ -78,8 +78,6 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
// Move one line down, from the border to the input line
chunks[1].y + 1,
)
//InputMode::Normal | InputMode::Select | InputMode::Popup =>
// Hide the cursor. `Frame` does this by default, so we don't need to do anything here
}

// Bottom two inner blocks
Expand All @@ -89,7 +87,7 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
.split(chunks[2]);

let subs: Vec<ListItem> = app
.subs[0]
.subs[app.subsindex]
.iter()
.enumerate()
.map(|(i, m)| {
Expand All @@ -98,7 +96,7 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
})
.collect();
let subs = List::new(subs)
.block(Block::default().borders(Borders::ALL).title("List"))
.block(Block::default().borders(Borders::ALL).title(format!("Subscribe {}",app.subsindex)))
.highlight_style(
Style::default()
.bg(Color::LightGreen)
Expand All @@ -118,10 +116,10 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
})
.collect();
let block =
List::new(messages).block(Block::default().borders(Borders::ALL).title("Messages"));
List::new(messages).block(Block::default().borders(Borders::ALL).title("Informations"));
f.render_widget(block, bottom_chunks[1]);
} else {
let block = Block::default().title("With borders").borders(Borders::ALL);
let block = Block::default().title("Informations None").borders(Borders::ALL);
f.render_widget(block, bottom_chunks[1]);
}
//};
Expand Down
102 changes: 44 additions & 58 deletions src/subscribe/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::utils;
use super::{Page, IFEXIT};
use crossterm::event::{self, Event, KeyCode};
use std::{env, io, process::Command};
use tui::widgets::ListState;
pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
if let Event::Key(key) = event::read()? {
match app.input_mode {
Expand All @@ -30,38 +31,7 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
},
InputMode::Editing => match key.code {
KeyCode::Enter => {
let input = vec![app.input.clone()];
let get_list = spider::get_the_key(input);
if let Ok(list) = get_list {
let mut storge: String = String::new();
storge.push('[');
storge.push('\n');
if !list[0].is_empty() {
//app.subs = list[0].clone();
app.stateoflist = true;
app.state[app.subsindex].select(Some(0));
for alist in &list[0] {
let information = spider::Information::new(alist.to_string());
app.informations[0].push(information.clone());
storge.push_str(information.get_the_json_node().as_str());
}
app.subs[0] = app
.informations[0]
.iter()
.map(|ainformation| {
spider::remove_quotation(ainformation.ps.clone())
})
.collect();
}
storge.pop();
storge.pop();
storge.push('\n');
storge.push(']');
utils::create_json_file(utils::Save::Storage, storge)
.unwrap_or_else(|err| panic!("err {}", err));
}

//app.subs.push(app.input.drain(..).collect());
app.input = "This should be a search bar".to_string();
}
KeyCode::Char(c) => {
app.input.push(c);
Expand All @@ -80,6 +50,8 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
//KeyCode::Left => app.unselect(),
KeyCode::Down => app.next(),
KeyCode::Up => app.previous(),
KeyCode::Left => app.left(),
KeyCode::Right => app.right(),
KeyCode::Esc => {
app.unselect();
app.input_mode = InputMode::Normal;
Expand Down Expand Up @@ -137,8 +109,8 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
let mut subscribe_json: String = "[\n\n".to_string();
for asub in &app.subscription {
subscribe_json.push_str(&format!(
"{{ \n\
\"url\": \"{}\"\n \
"{{\n \
\"url\": \"{}\"\n\
}},\n",
asub
));
Expand All @@ -151,32 +123,46 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
// .collect();
let get_list = spider::get_the_key(app.subscription.clone());
if let Ok(list) = get_list {
let mut storge: String = String::new();
storge.push('[');
storge.push_str("\n\n");
if !list.is_empty() && !list[0].is_empty() {
//app.subs = list[0].clone();
app.stateoflist = true;
app.state[app.subsindex].select(Some(0));
for alist in &list[0] {
let information = spider::Information::new(alist.to_string());
app.informations[0].push(information.clone());
storge.push_str(information.get_the_json_node().as_str());
if !list.is_empty(){
let mut storge: String = "[\n\n".to_string();
let mut subs : Vec<Vec<String>> =Vec::new();
let mut information :Vec<Vec<spider::Information>> = Vec::new();
let mut state: Vec<ListState>= Vec::new();
for lista in list {
let mut ainformation: Vec<spider::Information> = Vec::new();
//let mut asub: Vec<String> = Vec::new();
storge.push_str("[\n\n");
if !lista.is_empty() {
for alist in lista {
let inform = spider::Information::new(alist.to_string());
ainformation.push(inform.clone());
storge.push_str(&inform.get_the_json_node());

}
storge.pop();
storge.pop();
storge.push_str("\n ],");
}
state.push(ListState::default());
subs.push(ainformation
.iter()
.map(|ainfor| spider::remove_quotation(ainfor.ps.clone()))
.collect());
information.push(ainformation);

}
app.subs[0] = app
.informations[0]
.iter()
.map(|ainformation| {
spider::remove_quotation(ainformation.ps.clone())
})
.collect();
app.state = state;
app.subs = subs;
app.informations = information;
storge.pop();
storge.push_str("\n]");
utils::create_json_file(utils::Save::Storage, storge)
.unwrap_or_else(|err| panic!("err {}", err));
app.subsindex = 0;
app.state[0].select(Some(0));
app.stateoflist=true;

}
storge.pop();
storge.pop();
storge.push('\n');
storge.push(']');
utils::create_json_file(utils::Save::Storage, storge)
.unwrap_or_else(|err| panic!("err {}", err));
}
}
_ => {}
Expand Down
48 changes: 28 additions & 20 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::spider::Information;
use serde_json::{Value,json};
use serde_json::{json, Value};
use std::{
env,
fs::{self, File},
Expand Down Expand Up @@ -50,7 +50,8 @@ pub fn start_v2core() -> String {
Err(_) => {
let core = json!({
"v2core":"/usr/bin/v2ray"
}).to_string();
})
.to_string();
create_json_file(Save::V2ray, core.clone()).unwrap_or_else(|err| panic!("{}", err));
core
}
Expand Down Expand Up @@ -81,7 +82,7 @@ pub fn get_subs() -> Vec<String> {
}
subscribes
}
pub fn start() -> Vec<Information> {
pub fn start() -> Vec<Vec<Information>> {
create_storage_before();
let messages = match get_json(Save::Storage) {
Ok(output) => output,
Expand All @@ -95,23 +96,30 @@ pub fn start() -> Vec<Information> {
let v: Value = serde_json::from_str(messages.as_str()).unwrap();
let mut index = 0;
while v[index] != Value::Null {
let the_url = v[index]["url"].to_string();
let length = the_url.len();
let instore = &the_url[1..length - 1];
informations.push(Information {
urls: instore.to_string(),
func: v[index]["func"].to_string(),
add: v[index]["add"].to_string(),
aid: v[index]["aid"].to_string(),
host: v[index]["host"].to_string(),
id: v[index]["id"].to_string(),
net: v[index]["net"].to_string(),
path: v[index]["path"].to_string(),
port: v[index]["port"].to_string(),
ps: v[index]["ps"].to_string(),
tls: v[index]["tls"].to_string(),
typpe: v[index]["type"].to_string(),
});
let mut index2 = 0;
let w = v[index].clone();
let mut information = Vec::new();
while w[index2] != Value::Null {
let the_url = w[index2]["url"].to_string();
let length = the_url.len();
let instore = &the_url[1..length - 1];
information.push(Information {
urls: instore.to_string(),
func: w[index2]["func"].to_string(),
add: w[index2]["add"].to_string(),
aid: w[index2]["aid"].to_string(),
host: w[index2]["host"].to_string(),
id: w[index2]["id"].to_string(),
net: w[index2]["net"].to_string(),
path: w[index2]["path"].to_string(),
port: w[index2]["port"].to_string(),
ps: w[index2]["ps"].to_string(),
tls: w[index2]["tls"].to_string(),
typpe: w[index2]["type"].to_string(),
});
index2 += 1;
}
informations.push(information);
//let names = v[index]["ps"].to_string();
//start.add_item(remove_quotation(names), url);
index += 1;
Expand Down

0 comments on commit 650179f

Please sign in to comment.