]>
git.wh0rd.org - gnudebbugs.git/blob - src/gnudebbugs/ui/cli.py
1 # Copyright (C) 2021 Free Software Foundation, Inc.
3 # This program is free software: you can redistribute it and/or modify it under
4 # the terms of the GNU Lesser General Public License as published by the Free
5 # Software Foundation, either version 3 of the License, or at your option) any
8 # This program is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 # You should have received a copy of the GNU Lesser General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 """Command line interface UI."""
19 from typing
import Optional
25 """Command line interfacee."""
27 CSI_ERASE_LINE
= "\x1b[2K"
30 self
._clear
_line
_text
= self
.CSI_ERASE_LINE
+ "\r" if os
.isatty(1) else "\n"
32 def osc8_link(self
, url
: str, text
: str) -> str:
33 return f
"\x1b]8;;{url}\x07{text}\x1b]8;;\x07"
35 def _clear_line(self
, flush
: bool = False):
36 print(self
._clear
_line
_text
, end
='', flush
=flush
)
38 def status(self
, text
: Optional
[str] = None) -> None:
39 """Print status information."""
42 print(text
, end
='', flush
=True)
44 def interface_query(self
, client
, statuses
, bug_width
, summary_tags
, tags_width
, summary_states
, states_width
) -> None:
45 """Run the query interface."""
46 for bug
, status
in sorted(statuses
.items()):
47 # Severity levels all happen to start with a diff first letter.
48 sev
= status
["severity"][0]
50 self
.osc8_link(client
.link(bug
), f
"{bug:{bug_width}}"),
51 f
"{sev}{summary_tags[bug]:{tags_width}}{summary_states[bug]:{states_width}}",