GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — clibrowser/src/commands/select.rs at main · allthingssecurity/clibrowser

Expand file tree

/

select.rs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
90 lines (79 loc) · 2.29 KB
/

select.rs

Copy path

File metadata and controls

90 lines (79 loc) · 2.29 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use anyhow::Result;
use serde::Serialize;
use crate::cli::SelectArgs;
use crate::dom::Document;
use crate::error::BrowserError;
use crate::output::OutputConfig;
use crate::session::Session;
#[derive(Serialize)]
struct SelectResult {
count: usize,
results: Vec<SelectItem>,
}
#[derive(Serialize)]
struct SelectItem {
index: usize,
text: String,
#[serde(skip_serializing_if = "Option::is_none")]
html: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
attr_value: Option<String>,
attributes: std::collections::HashMap<String, String>,
}
pub fn execute(args: SelectArgs, session: &Session, out: &OutputConfig) -> Result<i32> {
let html = session
.page_html()
.ok_or(BrowserError::NoPageLoaded)?;
let doc = Document::parse(&html);
let elements = doc.select(&args.selector)?;
let mut items: Vec<SelectItem> = elements
.iter()
.map(|el| {
let attr_value = args.attr.as_ref().and_then(|a| el.attributes.get(a).cloned());
SelectItem {
index: el.index,
text: el.text.clone(),
html: if args.html { Some(el.html.clone()) } else { None },
attr_value,
attributes: el.attributes.clone(),
}
})
.collect();
// Apply index filter
if let Some(idx) = args.index {
if idx >= items.len() {
return Err(BrowserError::IndexOutOfRange {
index: idx,
count: items.len(),
}
.into());
}
items = vec![items.remove(idx)];
}
// Apply first filter
if args.first {
items.truncate(1);
}
// Apply limit
if let Some(limit) = args.limit {
items.truncate(limit);
}
if out.json {
out.print_json(&SelectResult {
count: items.len(),
results: items,
});
} else {
for item in &items {
let display = if let Some(ref av) = item.attr_value {
av.clone()
} else if args.html {
item.html.as_deref().unwrap_or("").to_string()
} else {
item.text.clone()
};
out.print_human(&format!("[{}] {}", item.index, display));
}
}
Ok(0)
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.