21 Commits
0.1.1 ... 0.1.5

Author SHA1 Message Date
Alexandr Bogomyakov
b264f3b823 Fix workflow. 2019-12-04 14:52:59 +03:00
Alexandr Bogomyakov
86a95efa49 Fix workflow. 2019-12-04 14:50:59 +03:00
Alexandr Bogomyakov
3e131088e6 Add env to workflow. 2019-12-04 14:30:56 +03:00
Alexandr Bogomyakov
f96467272b Add env to workflow. 2019-12-04 14:30:43 +03:00
Alexandr Bogomyakov
8cdaf4628b Add push action - build. 2019-12-04 14:23:28 +03:00
House of Vanity
23cc78cc0a Update README.md 2019-12-04 13:06:54 +03:00
House of Vanity
dec3226f41 Update README.md
Update readme.
2019-12-04 13:06:32 +03:00
House of Vanity
e085d55dde Create README.md 2019-12-04 12:58:26 +03:00
Alexandr Bogomyakov
17228e3ca8 Add screenshot 2019-12-04 12:57:00 +03:00
Ultra Desu
3b3f77a0e0 Merge colorize with player status 2019-12-03 23:53:21 +03:00
Alexandr Bogomyakov
f655e542fc Add player status icon. 2019-12-03 09:33:26 +03:00
Ultra Desu
5785b15a78 Colorize media player applet. 2019-11-30 16:21:33 +03:00
Ultra Desu
c69a95009d Add media player metadata. 2019-11-30 14:10:05 +03:00
Ultra Desu
b95183fd94 lifetime issue 2019-11-30 03:14:00 +03:00
Alexandr Bogomyakov
a9216ff630 Add dbus support 2019-11-29 18:17:57 +03:00
Alexandr Bogomyakov
b070d50bc7 Merge branch 'master' of github.com:house-of-vanity/tmux_helper 2019-11-28 18:00:10 +03:00
Alexandr Bogomyakov
139e7c7577 Linting 2019-11-28 18:00:00 +03:00
Alexandr Bogomyakov
23730088d5 Add dbus client. 2019-11-28 17:59:24 +03:00
House of Vanity
3a04d115bf Delete rust.yml 2019-11-25 12:31:33 +03:00
House of Vanity
971de9c6f0 Update release-upload.yml 2019-11-25 12:27:06 +03:00
House of Vanity
0e035e1066 Update and rename main.yml to release-upload.yml
Fix mime type
2019-11-24 03:32:50 +03:00
7 changed files with 168 additions and 38 deletions

BIN
.github/prev.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

20
.github/workflows/push-build.yml vendored Normal file
View File

@@ -0,0 +1,20 @@
name: Rust
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Pre-build
run: sudo apt install -y libdbus-1-dev pkg-config libdbus-1-3
- name: Build
run: cargo build --verbose --release
env:
RUST_BACKTRACE: 1
- name: Strip
run: strip target/release/tmux-helper

View File

@@ -8,12 +8,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Pre-build
run: apt install -y libdbus-1-dev pkg-config libdbus-1-3
- name: Build
run: cargo build --verbose --release
env:
RUST_BACKTRACE: 1
- name: Strip
run: strip target/release/tmux-helper
- name: Upload to release
uses: JasonEtco/upload-to-release@master
with:
args: target/release/tmux-helper
args: target/release/tmux-helper application/x-pie-executable
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,15 +0,0 @@
name: Rust
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

View File

@@ -6,3 +6,4 @@ edition = "2018"
[dependencies]
sys-info = "*"
dbus = "*"

16
README.md Normal file
View File

@@ -0,0 +1,16 @@
# Tmux helper
Small app that perform system check and print TMUX friendly output.
![Preview](.github/prev.png)
### Features:
1. `tmux-helper -cb` print cpu load with bar.
2. `tmux-helper -mb` print memory usage with bar.
3. `tmux-helper -p` show current player status using d-bus.
### Building
`cargo build --release`
or get binary on release page
### Customization
Colours are hardcoded but it's easy to change it. It defined as CONST in very beginning of main.rs file.

View File

@@ -1,17 +1,28 @@
use std::fs;
use std::env;
extern crate dbus;
use crate::dbus::blocking::stdintf::org_freedesktop_dbus::Properties;
use dbus::{arg, blocking::Connection};
use std::{env, fs, time::Duration};
use sys_info;
const LOW: &str = "#[fg=colour186]";
const MID: &str = "#[fg=colour208]";
const HIGH: &str = "#[fg=colour160]";
const LOW: &str = "#[fg=colour2]";
const MID: &str = "#[fg=colour3]";
const HIGH: &str = "#[fg=colour1]";
const END: &str = "#[fg=colour7]";
const TRACK_NAME: &str = "#[fg=colour3]";
const TRACK_ARTIST: &str = "#[fg=colour3]";
const TRACK_TIME: &str = "#[bg=colour252 fg=colour235 bold]";
fn read_file(file_path: &str) -> String {
fs::read_to_string(file_path)
.expect("Cant read file.")
struct TrackInfo {
title: String,
artist: String,
position: String,
duration: String,
status: String,
}
fn read_file(file_path: &str) -> String {
fs::read_to_string(file_path).expect("Cant read file.")
}
fn to_bar(value: i32, max: i32, low: f32, mid: f32) {
let mut bar = "".to_string();
@@ -26,7 +37,9 @@ fn to_bar(value: i32, max: i32, low: f32, mid: f32) {
for i in 0..max {
if i < value as i32 {
bar.push_str(&bar_sym);
} else {bar.push_str(" ")}
} else {
bar.push_str(" ")
}
}
bar.push_str(END);
bar.push_str("|");
@@ -39,9 +52,10 @@ fn mem_load_bar(bar_len: i32) {
Err(w) => panic!("{:?}", w),
Ok(mem_data) => memory = mem_data,
}
let len = ((memory.total - memory.avail) as f32 / (memory.total as f32) * bar_len as f32) as i32;
let len =
((memory.total - memory.avail) as f32 / (memory.total as f32) * bar_len as f32) as i32;
to_bar(len, bar_len, 0.7, 0.9);
print!("{:.0} MiB", memory.avail/1024);
print!("{:.0} MiB", memory.avail / 1024);
}
fn cpu_load_bar(bar_len: i32) {
@@ -55,22 +69,109 @@ fn cpu_load_bar(bar_len: i32) {
print!("{:.2} LA1", one);
}
fn player_info(player: &str) -> Result<TrackInfo, Box<dyn std::error::Error>> {
let conn = Connection::new_session()?;
let mut service: String = "org.mpris.MediaPlayer2.".to_owned();
service.push_str(player);
let proxy = conn.with_proxy(
service,
"/org/mpris/MediaPlayer2",
Duration::from_millis(5000),
);
let metadata: Box<dyn arg::RefArg> = proxy.get("org.mpris.MediaPlayer2.Player", "Metadata")?;
let mut iter = metadata.as_iter().unwrap();
let mut track_info = TrackInfo {
artist: "".to_string(),
title: "".to_string(),
position: "".to_string(),
duration: "".to_string(),
status: "".to_string(),
};
while let Some(key) = iter.next() {
if key.as_str() == Some("xesam:title") {
if let Some(title) = iter.next().unwrap().as_str() {
track_info.title = title.to_string();
}
}
if key.as_str() == Some("mpris:length") {
if let Some(length) = iter.next().unwrap().as_i64() {
track_info.duration = format_time(length / 1000000);
}
}
if key.as_str() == Some("xesam:artist") {
if let Some(mut artists) = iter.next().unwrap().as_iter() {
while let Some(artist) = artists.next() {
if let Some(mut line) = artist.as_iter() {
track_info.artist = line.next().unwrap().as_str().unwrap().to_string();
}
}
}
}
}
let position: Box<dyn arg::RefArg> = proxy.get("org.mpris.MediaPlayer2.Player", "Position")?;
track_info.position = format_time(position.as_i64().unwrap() / 1000000);
// ugly
let _status_text_box: Box<dyn arg::RefArg> =
proxy.get("org.mpris.MediaPlayer2.Player", "PlaybackStatus")?;
let _status_text = _status_text_box.as_str().unwrap();
match _status_text.as_ref() {
"Playing" => track_info.status = "".to_string(),
"Paused" => track_info.status = "".to_string(),
_ => track_info.status = "".to_string(),
};
Ok(track_info)
}
fn format_time(sec: i64) -> String {
let minutes = sec / 60;
let secondes = sec % 60;
let result = format!("{:02}:{:02}", minutes, secondes);
result.to_string()
}
fn main() {
let args: Vec<String> = env::args().collect();
let help_text: &str = "Available commands -mb, -cb";
match args.len() {
let args: Vec<String> = env::args().collect();
let help_text: &str = "Available commands -mb, -cb";
match args.len() {
1 => {
panic!(help_text);
},
2 => {
match args[1].as_ref() {
"-cb" => cpu_load_bar(15),
"-mb" => mem_load_bar(15),
_ => panic!(help_text),
}
}
2 => match args[1].as_ref() {
"-cb" => cpu_load_bar(15),
"-mb" => mem_load_bar(15),
"-p" => match player_info("cmus") {
Ok(mut track_info) => {
let title_len = 30;
let artist_len = 30;
if track_info.title.len() >= title_len {
track_info.title.truncate(title_len);
track_info.title.push_str("..");
}
if track_info.artist.len() >= artist_len {
track_info.artist.truncate(artist_len);
track_info.artist.push_str("..");
}
println!(
"#[none]#[bold]{}{}{}#[none]{} - {}{} {}[{}/{}] {} {}",
TRACK_NAME,
track_info.title,
END,
TRACK_ARTIST,
track_info.artist,
END,
TRACK_TIME,
track_info.position,
track_info.duration,
track_info.status,
END,
);
}
Err(_e) => println!("No music playing"),
},
_ => panic!(help_text),
},
_ => {
panic!(help_text);
}
}
}
}