connect sourceview5

This commit is contained in:
yggverse 2024-12-08 15:11:57 +02:00
parent 614aa1d71a
commit c1fc022643
5 changed files with 29 additions and 11 deletions

View File

@ -41,6 +41,10 @@ version = "5.2.0"
[dependencies.ansi-parser] [dependencies.ansi-parser]
version = "0.9.1" version = "0.9.1"
[dependencies.sourceview]
package = "sourceview5"
version = "0.9.1"
# development # development
[patch.crates-io] [patch.crates-io]
# ggemini = { path = "ggemini" } # ggemini = { path = "ggemini" }

View File

@ -97,7 +97,7 @@ GTK 4 / Libadwaita client written in Rust
* [ ] `file://` - localhost browser * [ ] `file://` - localhost browser
* [ ] System * [ ] System
* [ ] `config:` - low-level key/value settings editor * [ ] `config:` - low-level key/value settings editor
* [x] `view-source:` - page source viewer (where supported) * [x] `source:` - page source viewer (where supported)
### Media types ### Media types
@ -129,13 +129,14 @@ GTK 4 / Libadwaita client written in Rust
* GDK PixBuf `2.42` * GDK PixBuf `2.42`
* Glib `2.80` * Glib `2.80`
* GTK `4.14` * GTK `4.14`
* GtkSourceView `5.14`
* Libadwaita `1.5` (Ubuntu 24.04+) * Libadwaita `1.5` (Ubuntu 24.04+)
#### Debian #### Debian
``` bash ``` bash
sudo apt install git curl build-essential\ sudo apt install git curl build-essential\
libgtk-4-dev libadwaita-1-dev\ libgtk-4-dev libgtksourceview-5-dev libadwaita-1-dev\
libsqlite3-dev libssl-dev libsqlite3-dev libssl-dev
``` ```
@ -143,7 +144,7 @@ sudo apt install git curl build-essential\
``` bash ``` bash
sudo dnf install git curl gcc\ sudo dnf install git curl gcc\
gtk4-devel libadwaita-devel\ gtk4-devel gtksourceview5-devel libadwaita-devel\
sqlite-devel openssl-devel sqlite-devel openssl-devel
``` ```

View File

@ -11,11 +11,17 @@ impl About {
// Collect debug info // Collect debug info
let debug = &[ let debug = &[
format!( format!(
"GTK {}.{}.{}", "Gtk {}.{}.{}",
gtk::major_version(), gtk::major_version(),
gtk::minor_version(), gtk::minor_version(),
gtk::micro_version() gtk::micro_version()
), ),
format!(
"GtkSourceView {}.{}.{}",
sourceview::major_version(),
sourceview::minor_version(),
sourceview::micro_version()
),
format!("SQLite {}", sqlite::version()), format!("SQLite {}", sqlite::version()),
// @TODO // @TODO
]; ];

View File

@ -198,8 +198,8 @@ impl Page {
}; };
// Detect source view mode, return `request` string prepared for route // Detect source view mode, return `request` string prepared for route
let (request, is_view_source) = match request.strip_prefix("view-source:") { let (request, is_view_source) = match request.strip_prefix("source:") {
Some(postfix) => (gformat!("{}", postfix.to_string()), true), Some(postfix) => (GString::from(postfix), true),
None => (request, false), None => (request, false),
}; };

View File

@ -1,22 +1,29 @@
use gtk::{TextBuffer, TextView}; use sourceview::{Buffer, StyleScheme, View};
const MARGIN: i32 = 8; const MARGIN: i32 = 8;
pub struct Source { pub struct Source {
pub text_view: TextView, pub text_view: View,
} }
impl Source { impl Source {
pub fn new(data: &str) -> Self { pub fn new(data: &str) -> Self {
Self { Self {
text_view: TextView::builder() text_view: View::builder()
.bottom_margin(MARGIN) .bottom_margin(MARGIN)
.buffer(&TextBuffer::builder().text(data).build()) .buffer(
&Buffer::builder()
.text(data)
.style_scheme(&StyleScheme::builder().build()) // adaptive
.highlight_syntax(true)
.build(),
)
.cursor_visible(false) .cursor_visible(false)
.editable(false) .editable(false)
.left_margin(MARGIN) .left_margin(MARGIN)
.monospace(true) .monospace(true)
.right_margin(MARGIN) .right_margin(MARGIN)
.show_line_marks(true)
.show_line_numbers(true)
.top_margin(MARGIN) .top_margin(MARGIN)
.vexpand(true) .vexpand(true)
.build(), .build(),