afrish/theme.rs
1//! Themes - functions to list and set the overall theme (look and feel) of
2//! the Tk program.
3//!
4//! * also see the Tk [manual](https://www.tcl-lang.org/man/tcl8.6/TkCmd/ttk_style.htm#M17)
5
6use super::wish;
7
8/// Returns a list of the current themes.
9///
10/// For example:
11///
12/// ```ignore
13/// let themes = afrish::theme_names();
14/// println!("{} available themes: ", themes.len());
15/// for theme in themes {
16/// println!(" - {}", theme);
17/// }
18/// ```
19///
20/// Lists the themes (on Linux):
21///
22/// ```text
23/// 4 available themes:
24/// - clam
25/// - alt
26/// - default
27/// - classic
28/// ```
29///
30pub fn theme_names() -> Vec<String> {
31 let themes = wish::ask_wish("puts [ttk::style theme names] ; flush stdout");
32
33 let mut result: Vec<String> = vec![];
34 for theme in themes.split_whitespace() {
35 result.push(String::from(theme));
36 }
37
38 result
39}
40
41/// Sets the current theme to the given theme-name
42pub fn use_theme(name: &str) {
43 let msg = format!("ttk::style theme use {}", name);
44 wish::tell_wish(&msg);
45}