Skip to content

Commit 650179f

Browse files
author
cht
committed
first tag
1 parent 2fdfd96 commit 650179f

6 files changed

Lines changed: 130 additions & 91 deletions

File tree

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,28 @@
22

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

5-
TODO
5+
tui界面的v2ray
6+
7+
按键
8+
9+
* h
10+
* 按h出设置界面,设置界面里面有两个设置
11+
* v2raycore
12+
* 订阅,当在第二个设置里面添加了订阅后按下键可以选中订阅,d键删除
13+
* e
14+
* TODO, 计划作为设置
15+
* s
16+
* 进入选择节点界面
17+
* 此界面按F5可以运行core,ese+q退出后设置代理可以访问互联网
18+
* 此界面左右键可以切换订阅
19+
* ese + q
20+
* 此两键各种退出
21+
22+
使用
23+
24+
```sh
25+
export http_proxy=http://127.0.0.1:8889
26+
export https_proxy=http://127.0.0.1:8889
27+
```
28+
29+
然后可以联网

src/state.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::io;
77
use std::io::Stdout;
88
use tui::backend::CrosstermBackend;
99
use tui::Terminal;
10+
use tui::widgets::ListState;
1011
#[derive(Clone, Copy)]
1112
pub enum Page {
1213
SubScribe = 0,
@@ -25,13 +26,22 @@ pub fn run_app(terminal: &mut Terminal<MyBackend>) -> io::Result<()> {
2526
let mut appsub = AppSub::default();
2627
let informations = utils::start();
2728
if !informations.is_empty() {
28-
appsub.subs[0] = informations
29+
//appsub.subs[0] = informations[0]
30+
// .iter()
31+
// .map(|amessage| spider::remove_quotation(amessage.ps.clone()))
32+
// .collect();
33+
appsub.subs = informations
2934
.iter()
30-
.map(|amessage| spider::remove_quotation(amessage.ps.clone()))
35+
.map(|ainformation| ainformation
36+
.iter()
37+
.map(|message| spider::remove_quotation(message.ps.clone()))
38+
.collect())
3139
.collect();
3240
appsub.stateoflist = true;
33-
appsub.state[0].select(Some(0));
34-
appsub.informations[0] = informations;
41+
let len = informations.len();
42+
appsub.state = vec![ListState::default();len];
43+
//appsub.state[0].select(Some(0));
44+
appsub.informations = informations.clone();
3545
}
3646
appsub.subscription = utils::get_subs();
3747
appsub.settings_input[0] = utils::start_v2core();

src/subscribe/appsub.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,20 @@ impl AppSub {
6464
};
6565
self.state[self.subsindex].select(Some(i));
6666
}
67-
67+
pub fn left(&mut self){
68+
if self.subsindex == 0 {
69+
self.subsindex = self.state.len()-1;
70+
} else {
71+
self.subsindex -=1;
72+
}
73+
}
74+
pub fn right(&mut self){
75+
if self.subsindex >= self.state.len() -1 {
76+
self.subsindex = 0;
77+
} else {
78+
self.subsindex +=1;
79+
}
80+
}
6881
pub fn unselect(&mut self) {
6982
self.state[self.subsindex].select(None);
7083
}

src/subscribe/render.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
6868
InputMode::Editing => Style::default().fg(Color::Yellow),
6969
_ => Style::default(),
7070
})
71-
.block(Block::default().borders(Borders::ALL).title("Input"));
71+
.block(Block::default().borders(Borders::ALL).title("Search bar"));
7272
f.render_widget(input, chunks[1]);
7373
if let InputMode::Editing = app.input_mode {
7474
// Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
@@ -78,8 +78,6 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
7878
// Move one line down, from the border to the input line
7979
chunks[1].y + 1,
8080
)
81-
//InputMode::Normal | InputMode::Select | InputMode::Popup =>
82-
// Hide the cursor. `Frame` does this by default, so we don't need to do anything here
8381
}
8482

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

9189
let subs: Vec<ListItem> = app
92-
.subs[0]
90+
.subs[app.subsindex]
9391
.iter()
9492
.enumerate()
9593
.map(|(i, m)| {
@@ -98,7 +96,7 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
9896
})
9997
.collect();
10098
let subs = List::new(subs)
101-
.block(Block::default().borders(Borders::ALL).title("List"))
99+
.block(Block::default().borders(Borders::ALL).title(format!("Subscribe {}",app.subsindex)))
102100
.highlight_style(
103101
Style::default()
104102
.bg(Color::LightGreen)
@@ -118,10 +116,10 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
118116
})
119117
.collect();
120118
let block =
121-
List::new(messages).block(Block::default().borders(Borders::ALL).title("Messages"));
119+
List::new(messages).block(Block::default().borders(Borders::ALL).title("Informations"));
122120
f.render_widget(block, bottom_chunks[1]);
123121
} else {
124-
let block = Block::default().title("With borders").borders(Borders::ALL);
122+
let block = Block::default().title("Informations None").borders(Borders::ALL);
125123
f.render_widget(block, bottom_chunks[1]);
126124
}
127125
//};

src/subscribe/state.rs

Lines changed: 44 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::utils;
44
use super::{Page, IFEXIT};
55
use crossterm::event::{self, Event, KeyCode};
66
use std::{env, io, process::Command};
7+
use tui::widgets::ListState;
78
pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
89
if let Event::Key(key) = event::read()? {
910
match app.input_mode {
@@ -30,38 +31,7 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
3031
},
3132
InputMode::Editing => match key.code {
3233
KeyCode::Enter => {
33-
let input = vec![app.input.clone()];
34-
let get_list = spider::get_the_key(input);
35-
if let Ok(list) = get_list {
36-
let mut storge: String = String::new();
37-
storge.push('[');
38-
storge.push('\n');
39-
if !list[0].is_empty() {
40-
//app.subs = list[0].clone();
41-
app.stateoflist = true;
42-
app.state[app.subsindex].select(Some(0));
43-
for alist in &list[0] {
44-
let information = spider::Information::new(alist.to_string());
45-
app.informations[0].push(information.clone());
46-
storge.push_str(information.get_the_json_node().as_str());
47-
}
48-
app.subs[0] = app
49-
.informations[0]
50-
.iter()
51-
.map(|ainformation| {
52-
spider::remove_quotation(ainformation.ps.clone())
53-
})
54-
.collect();
55-
}
56-
storge.pop();
57-
storge.pop();
58-
storge.push('\n');
59-
storge.push(']');
60-
utils::create_json_file(utils::Save::Storage, storge)
61-
.unwrap_or_else(|err| panic!("err {}", err));
62-
}
63-
64-
//app.subs.push(app.input.drain(..).collect());
34+
app.input = "This should be a search bar".to_string();
6535
}
6636
KeyCode::Char(c) => {
6737
app.input.push(c);
@@ -80,6 +50,8 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
8050
//KeyCode::Left => app.unselect(),
8151
KeyCode::Down => app.next(),
8252
KeyCode::Up => app.previous(),
53+
KeyCode::Left => app.left(),
54+
KeyCode::Right => app.right(),
8355
KeyCode::Esc => {
8456
app.unselect();
8557
app.input_mode = InputMode::Normal;
@@ -137,8 +109,8 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
137109
let mut subscribe_json: String = "[\n\n".to_string();
138110
for asub in &app.subscription {
139111
subscribe_json.push_str(&format!(
140-
"{{ \n\
141-
\"url\": \"{}\"\n \
112+
"{{\n \
113+
\"url\": \"{}\"\n\
142114
}},\n",
143115
asub
144116
));
@@ -151,32 +123,46 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
151123
// .collect();
152124
let get_list = spider::get_the_key(app.subscription.clone());
153125
if let Ok(list) = get_list {
154-
let mut storge: String = String::new();
155-
storge.push('[');
156-
storge.push_str("\n\n");
157-
if !list.is_empty() && !list[0].is_empty() {
158-
//app.subs = list[0].clone();
159-
app.stateoflist = true;
160-
app.state[app.subsindex].select(Some(0));
161-
for alist in &list[0] {
162-
let information = spider::Information::new(alist.to_string());
163-
app.informations[0].push(information.clone());
164-
storge.push_str(information.get_the_json_node().as_str());
126+
if !list.is_empty(){
127+
let mut storge: String = "[\n\n".to_string();
128+
let mut subs : Vec<Vec<String>> =Vec::new();
129+
let mut information :Vec<Vec<spider::Information>> = Vec::new();
130+
let mut state: Vec<ListState>= Vec::new();
131+
for lista in list {
132+
let mut ainformation: Vec<spider::Information> = Vec::new();
133+
//let mut asub: Vec<String> = Vec::new();
134+
storge.push_str("[\n\n");
135+
if !lista.is_empty() {
136+
for alist in lista {
137+
let inform = spider::Information::new(alist.to_string());
138+
ainformation.push(inform.clone());
139+
storge.push_str(&inform.get_the_json_node());
140+
141+
}
142+
storge.pop();
143+
storge.pop();
144+
storge.push_str("\n ],");
145+
}
146+
state.push(ListState::default());
147+
subs.push(ainformation
148+
.iter()
149+
.map(|ainfor| spider::remove_quotation(ainfor.ps.clone()))
150+
.collect());
151+
information.push(ainformation);
152+
165153
}
166-
app.subs[0] = app
167-
.informations[0]
168-
.iter()
169-
.map(|ainformation| {
170-
spider::remove_quotation(ainformation.ps.clone())
171-
})
172-
.collect();
154+
app.state = state;
155+
app.subs = subs;
156+
app.informations = information;
157+
storge.pop();
158+
storge.push_str("\n]");
159+
utils::create_json_file(utils::Save::Storage, storge)
160+
.unwrap_or_else(|err| panic!("err {}", err));
161+
app.subsindex = 0;
162+
app.state[0].select(Some(0));
163+
app.stateoflist=true;
164+
173165
}
174-
storge.pop();
175-
storge.pop();
176-
storge.push('\n');
177-
storge.push(']');
178-
utils::create_json_file(utils::Save::Storage, storge)
179-
.unwrap_or_else(|err| panic!("err {}", err));
180166
}
181167
}
182168
_ => {}

src/utils.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spider::Information;
2-
use serde_json::{Value,json};
2+
use serde_json::{json, Value};
33
use std::{
44
env,
55
fs::{self, File},
@@ -50,7 +50,8 @@ pub fn start_v2core() -> String {
5050
Err(_) => {
5151
let core = json!({
5252
"v2core":"/usr/bin/v2ray"
53-
}).to_string();
53+
})
54+
.to_string();
5455
create_json_file(Save::V2ray, core.clone()).unwrap_or_else(|err| panic!("{}", err));
5556
core
5657
}
@@ -81,7 +82,7 @@ pub fn get_subs() -> Vec<String> {
8182
}
8283
subscribes
8384
}
84-
pub fn start() -> Vec<Information> {
85+
pub fn start() -> Vec<Vec<Information>> {
8586
create_storage_before();
8687
let messages = match get_json(Save::Storage) {
8788
Ok(output) => output,
@@ -95,23 +96,30 @@ pub fn start() -> Vec<Information> {
9596
let v: Value = serde_json::from_str(messages.as_str()).unwrap();
9697
let mut index = 0;
9798
while v[index] != Value::Null {
98-
let the_url = v[index]["url"].to_string();
99-
let length = the_url.len();
100-
let instore = &the_url[1..length - 1];
101-
informations.push(Information {
102-
urls: instore.to_string(),
103-
func: v[index]["func"].to_string(),
104-
add: v[index]["add"].to_string(),
105-
aid: v[index]["aid"].to_string(),
106-
host: v[index]["host"].to_string(),
107-
id: v[index]["id"].to_string(),
108-
net: v[index]["net"].to_string(),
109-
path: v[index]["path"].to_string(),
110-
port: v[index]["port"].to_string(),
111-
ps: v[index]["ps"].to_string(),
112-
tls: v[index]["tls"].to_string(),
113-
typpe: v[index]["type"].to_string(),
114-
});
99+
let mut index2 = 0;
100+
let w = v[index].clone();
101+
let mut information = Vec::new();
102+
while w[index2] != Value::Null {
103+
let the_url = w[index2]["url"].to_string();
104+
let length = the_url.len();
105+
let instore = &the_url[1..length - 1];
106+
information.push(Information {
107+
urls: instore.to_string(),
108+
func: w[index2]["func"].to_string(),
109+
add: w[index2]["add"].to_string(),
110+
aid: w[index2]["aid"].to_string(),
111+
host: w[index2]["host"].to_string(),
112+
id: w[index2]["id"].to_string(),
113+
net: w[index2]["net"].to_string(),
114+
path: w[index2]["path"].to_string(),
115+
port: w[index2]["port"].to_string(),
116+
ps: w[index2]["ps"].to_string(),
117+
tls: w[index2]["tls"].to_string(),
118+
typpe: w[index2]["type"].to_string(),
119+
});
120+
index2 += 1;
121+
}
122+
informations.push(information);
115123
//let names = v[index]["ps"].to_string();
116124
//start.add_item(remove_quotation(names), url);
117125
index += 1;

0 commit comments

Comments
 (0)