Skip to content

Commit 94122f4

Browse files
author
cht
committed
core location set
1 parent 93bbd82 commit 94122f4

3 files changed

Lines changed: 52 additions & 23 deletions

File tree

src/main.rs

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum InputMode {
3131
Editing,
3232
Select,
3333
Popup,
34+
PopupEdit,
3435
}
3536

3637
/// App holds the state of the application
@@ -152,6 +153,11 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
152153
KeyCode::Char('q') => {
153154
return Ok(());
154155
}
156+
KeyCode::Char('h') => {
157+
//app.input = app.index.as_ref().unwrap().to_string();
158+
app.show_popup = true;
159+
app.input_mode = InputMode::Popup;
160+
}
155161
_ => {}
156162
},
157163
InputMode::Editing => match key.code {
@@ -207,7 +213,8 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
207213
storge.pop();
208214
storge.push('\n');
209215
storge.push(']');
210-
if let Err(err) = utils::create_json_file(storge) {
216+
if let Err(err) = utils::create_json_file(utils::Save::Storage, storge)
217+
{
211218
panic!("err {}", err);
212219
};
213220
}
@@ -234,21 +241,29 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
234241
KeyCode::Esc => {
235242
app.input_mode = InputMode::Normal;
236243
}
237-
KeyCode::Enter => {
238-
//app.input = app.index.as_ref().unwrap().to_string();
239-
app.show_popup = true;
240-
app.input_mode = InputMode::Popup;
241-
}
244+
242245
_ => {}
243246
}
244247
} else {
245248
app.input_mode = InputMode::Normal;
246249
}
247250
}
248251
InputMode::Popup => {
249-
if let KeyCode::Char('q') = key.code {
250-
app.input_mode = InputMode::Select;
251-
app.show_popup = false;
252+
match key.code {
253+
KeyCode::Char('q') => {
254+
app.input_mode = InputMode::Normal;
255+
app.show_popup = false;
256+
},
257+
KeyCode::Char('e') => {
258+
app.input_mode = InputMode::PopupEdit;
259+
},
260+
_ => {}
261+
}
262+
}
263+
InputMode::PopupEdit => {
264+
match key.code {
265+
KeyCode::Char('q') => app.input_mode = InputMode::Popup,
266+
_ => {}
252267
}
253268
}
254269
}
@@ -271,7 +286,7 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
271286
.split(f.size());
272287

273288
let (msg, style) = match app.input_mode {
274-
InputMode::Normal | InputMode::Popup => (
289+
InputMode::Normal | InputMode::Popup | InputMode::PopupEdit => (
275290
vec![
276291
Span::raw("Press "),
277292
Span::styled("q", Style::default().add_modifier(Modifier::BOLD)),
@@ -311,16 +326,12 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
311326

312327
let input = Paragraph::new(app.input.as_ref())
313328
.style(match app.input_mode {
314-
InputMode::Normal | InputMode::Select | InputMode::Popup => Style::default(),
315329
InputMode::Editing => Style::default().fg(Color::Yellow),
330+
_ => Style::default(),
316331
})
317332
.block(Block::default().borders(Borders::ALL).title("Input"));
318333
f.render_widget(input, chunks[1]);
319334
match app.input_mode {
320-
InputMode::Normal | InputMode::Select | InputMode::Popup =>
321-
// Hide the cursor. `Frame` does this by default, so we don't need to do anything here
322-
{}
323-
324335
InputMode::Editing => {
325336
// Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
326337
f.set_cursor(
@@ -330,6 +341,9 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
330341
chunks[1].y + 1,
331342
)
332343
}
344+
//InputMode::Normal | InputMode::Select | InputMode::Popup =>
345+
// Hide the cursor. `Frame` does this by default, so we don't need to do anything here
346+
_ => {}
333347
}
334348

335349
// Bottom two inner blocks
@@ -378,10 +392,17 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
378392
//f.render_widget(*block, bottom_chunks[0]);
379393

380394
if app.show_popup {
381-
let block = Block::default().title("About port").borders(Borders::ALL);
395+
//let block = Block::default().title("About port").borders(Borders::ALL);
396+
let inputpop = Paragraph::new(app.input.as_ref())
397+
.style(match app.input_mode {
398+
InputMode::PopupEdit => Style::default().fg(Color::Yellow),
399+
_ => Style::default(),
400+
})
401+
.block(Block::default().borders(Borders::ALL).title("Input"));
402+
//f.render_widget(input, chunks[1]);
382403
let area = centered_rect(60, 20, f.size());
383404
f.render_widget(Clear, area); //this clears out the background
384-
f.render_widget(block, area);
405+
f.render_widget(inputpop, area);
385406
}
386407
}
387408
fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {

src/spider.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ impl Information {
7777
output.push(format!("func: {}", self.func));
7878
output.push(format!("urls: {}", self.urls));
7979
output.push(format!("add: {}", self.add));
80-
output.push(format!("aid: {}", self.aid));
81-
output.push(format!("tls: {}", self.tls));
82-
output.push(format!("type: {}", self.typpe));
80+
output.push(format!("port: {}", self.port));
81+
output.push(format!("name: {}", self.ps));
8382
output
8483
}
8584
fn get_the_link(&self) -> String {

src/utils.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ use std::{
88
path::Path,
99
result::Result,
1010
};
11+
pub enum Save{
12+
Storage,
13+
Running,
14+
V2ray,
15+
}
1116
fn create_storage_before() {
1217
let home = env::var("HOME").unwrap();
1318
fs::create_dir_all(home + "/.config/tv2ray").unwrap();
1419
}
15-
pub fn create_json_file(input: String) -> Result<(), Error> {
20+
pub fn create_json_file(save:Save,input: String) -> Result<(), Error> {
1621
let home = env::var("HOME").unwrap();
17-
let location = format!("{}/.config/tv2ray/storage.json", home);
22+
let location = match save {
23+
Save::Storage => format!("{}/.config/tv2ray/storage.json", home),
24+
Save::Running => format!("{}/.config/tv2ray/running.json",home),
25+
Save::V2ray => format!("{}/.config/tv2ray/v2core.json",home),
26+
};
1827
let path = Path::new(location.as_str());
1928
let mut file = File::create(&path)?;
2029
//let storge: String = input;
@@ -34,7 +43,7 @@ pub fn start() -> Vec<Information> {
3443
let messages = match get_json() {
3544
Ok(output) => output,
3645
Err(_) => {
37-
if let Err(err) = create_json_file("[]".to_string()) {
46+
if let Err(err) = create_json_file(Save::Storage,"[]".to_string()) {
3847
panic!("{}", err);
3948
};
4049
"[]".to_string()

0 commit comments

Comments
 (0)