Skip to content

Commit f64d170

Browse files
Shorten hashes in kup list in narrow terminal (#125)
Co-authored-by: Andrei Văcaru <16517508+anvacaru@users.noreply.github.com>
1 parent 2ee30fe commit f64d170

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/kup/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import configparser
22
import json
33
import os
4+
import shutil
45
import subprocess
56
import sys
67
import textwrap
@@ -55,6 +56,8 @@
5556
KUP_DIR = os.path.split(os.path.abspath(__file__))[0] # i.e. /path/to/dir/
5657
VERBOSE = False
5758

59+
TERMINAL_WIDTH, _ = shutil.get_terminal_size((80, 20))
60+
5861
available_packages: list[GithubPackage] = [
5962
GithubPackage('runtimeverification', 'kup', PackageName('kup')),
6063
GithubPackage('runtimeverification', 'k', PackageName('k')),
@@ -378,7 +381,7 @@ def list_package(
378381
table_data = [['Package name (alias)', 'Installed version', 'Status'],] + [
379382
[
380383
str(PackageName(alias, p.package_name.ext).pretty_name),
381-
f'{p.commit}{" (" + p.tag + ")" if p.tag else ""}'
384+
f'{p.commit[:7] if TERMINAL_WIDTH < 80 else p.commit}{" (" + p.tag + ")" if p.tag else ""}'
382385
if type(p) == ConcretePackage
383386
else '\033[3mlocal checkout\033[0m'
384387
if type(p) == LocalPackage

0 commit comments

Comments
 (0)