Skip to content

Commit

Permalink
Fix process and thread max width
Browse files Browse the repository at this point in the history
  • Loading branch information
flxoacn committed Jun 7, 2024
1 parent 071eedb commit 5802e6a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
50 changes: 26 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ device during development. The `logcat` subcommand of `adb` allows access to `An
tries to give access to those logs in a convenient way including post processing capabilities. The main feature probably
is a painted and reformatted view. `rogcat` can read logs from

* running `adb logcat` (default)
* a custom command (`stdout`, `stderr`)
* one or multiple files
* `stdin`
* connect to TCP port
* A SocketCAN CAN device (Linux only)
- running `adb logcat` (default)
- a custom command (`stdout`, `stderr`)
- one or multiple files
- `stdin`
- connect to TCP port
- A SocketCAN CAN device (Linux only)

The processing steps within a `rogcat` run include parsing of the input stream and applying filters (if provided).
`rogcat` comes with a set of implemented in and output formats:

* `csv:` Comma separated values
* `raw:` Record (line) as captured
* `html:` A static single page html with a static table. This option cannot be used as input format. The page layout needs some love...
* `human:` A human friendly colored column based format. See screenshot
* `json:` Single line JSON
- `csv:` Comma separated values
- `raw:` Record (line) as captured
- `html:` A static single page html with a static table. This option cannot be used as input format. The page layout needs some love...
- `human:` A human friendly colored column based format. See screenshot
- `json:` Single line JSON

Except the `human` and `html` format the output of `rogcat` is parseable by `rogcat`.

![Screenshot](/screenshot.png)

## Examples

The following examples show a subset of `rogcat's` features. *Please read `--help`!*
The following examples show a subset of `rogcat's` features. _Please read `--help`!_

### Live

Expand All @@ -57,7 +57,7 @@ Process `stdout` and `stderr` of `command`:

### Filter

Display logs from `adb logcat` and filter on records where the tag matches `^ABC.*` along with *not* `X` and the message includes `pattern`:
Display logs from `adb logcat` and filter on records where the tag matches `^ABC.*` along with _not_ `X` and the message includes `pattern`:

`rogcat -t "^ADB.*" -t \!X -m pattern`

Expand Down Expand Up @@ -142,14 +142,14 @@ On Debian based systems the package `libudev-dev` (and it's dependencies) is req
When `rogcat` runs without any command supplied it defaults to running `adb logcat -b all`. The following options
can be overwritten in the `rogcat` config file `config.toml`. The location of the config file is platform specific:

* MacOS: `$HOME/Library/Preferences/rogcat/config.toml`
* Linux: `$HOME/.config/rogcat/config.toml`
* Windows: `%HOME%/AppData/Roaming/rogcat/config.toml`
- MacOS: `$HOME/Library/Preferences/rogcat/config.toml`
- Linux: `$HOME/.config/rogcat/config.toml`
- Windows: `%HOME%/AppData/Roaming/rogcat/config.toml`

### Restart

By default `rogcat` restarts `adb logcat` when that one exits. This is intentional behavior to make `rogcat` reconnect
on device power cycles or disconnect/reconnects. A `Windows 7` bug prevents `rogcat` from restarting `adb`. Place
on device power cycles or disconnect/reconnects. A `Windows 7` bug prevents `rogcat` from restarting `adb`. Place
`restart = false` in the configuration file mentioned above to make `rogcat` exit when `adb` exits.

### Buffer
Expand All @@ -166,12 +166,14 @@ buffer = ["main", "events"]
Some parameters of the `human` format are adjustable via the config file:

```
terminal_tag_width = 20
terminal_show_date = false
terminal_hide_timestamp = true
terminal_bright_colors = false
terminal_color = never
terminal_hide_timestamp = true
terminal_process_width_max = 16
terminal_thread_width_max = 16
terminal_no_dimm = true
terminal_bright_colors = false
terminal_show_date = false
terminal_tag_width = 20
```

## Profiles
Expand All @@ -180,9 +182,9 @@ Optionally `rogcat` reads a (`toml` formated) configuration file if present. Thi
('-p') and settings. The possible options in the configuration file are a subset of the command line options. The configuration
file is read from the location set in the environment variable `ROGCAT_PROFILES` or a fixed pathes depending on your OS:

* MacOS: `$HOME/Library/Preferences/rogcat/profiles.toml`
* Linux: `$HOME/.config/rogcat/profiles.toml`
* Windows: `%HOME%/AppData/Roaming/rogcat/profiles.toml`
- MacOS: `$HOME/Library/Preferences/rogcat/profiles.toml`
- Linux: `$HOME/.config/rogcat/profiles.toml`
- Windows: `%HOME%/AppData/Roaming/rogcat/profiles.toml`

The environment variable overrules the default path. See `rogcat profiles --help` or `rogcat profiles --examples`.

Expand Down
29 changes: 21 additions & 8 deletions src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ struct Human {
date_format: Option<(&'static str, usize)>,
highlight: Vec<Regex>,
process_width: usize,
max_process_width: usize,
process_width_max: usize,
tag_width: Option<usize>,
thread_width: usize,
max_thread_width: usize,
thread_width_max: usize,
dimm_color: Option<Color>,
bright_colors: bool,
}
Expand Down Expand Up @@ -119,6 +119,8 @@ impl Human {

let bright_colors = args.is_present("bright_colors")
|| config_get("terminal_bright_colors").unwrap_or(false);
let thread_width_max = config_get("terminal_thread_width_max").unwrap_or(16);
let process_width_max = config_get("terminal_process_width_max").unwrap_or(16);

Human {
writer: BufferWriter::stdout(color),
Expand All @@ -127,9 +129,9 @@ impl Human {
date_format,
tag_width,
process_width: 0,
max_process_width: 16,
process_width_max,
thread_width: 0,
max_thread_width: 16,
thread_width_max,
bright_colors,
}
}
Expand Down Expand Up @@ -202,19 +204,30 @@ impl Human {

self.process_width = min(
max(self.process_width, record.process.chars().count()),
self.max_process_width,
self.process_width_max,
);
let pid = if record.process.is_empty() {
" ".repeat(self.process_width)
} else {
format!("{:<width$}", record.process, width = self.process_width)
let process = if record.process.chars().count() > self.process_width {
&record.process[..self.process_width]
} else {
record.process.as_str()
};
format!("{:<width$}", process, width = self.process_width)
};

self.thread_width = min(
max(self.thread_width, record.thread.chars().count()),
self.max_thread_width,
self.thread_width_max,
);
let tid = if !record.thread.is_empty() {
format!(" {:>width$}", record.thread, width = self.thread_width)
let thread = if record.thread.chars().count() > self.thread_width {
&record.thread[..self.thread_width]
} else {
record.thread.as_str()
};
format!(" {:>width$}", thread, width = self.thread_width)
} else if self.thread_width != 0 {
" ".repeat(self.thread_width + 1)
} else {
Expand Down

0 comments on commit 5802e6a

Please sign in to comment.