mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Set table width to current width of terminal
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
parent
d74184f46b
commit
b1c5d1c945
6 changed files with 35 additions and 5 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <Extensions.h>
|
||||
#include <ExtensionsTable.h>
|
||||
#include <FS.h>
|
||||
#include <timew.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
ExtensionsTable::Builder ExtensionsTable::builder ()
|
||||
|
@ -44,9 +45,10 @@ ExtensionsTable::Builder& ExtensionsTable::Builder::withExtensions (const Extens
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
Table ExtensionsTable::Builder::build ()
|
||||
{
|
||||
Table table;
|
||||
int terminalWidth = getTerminalWidth ();
|
||||
|
||||
table.width (1024);
|
||||
Table table;
|
||||
table.width (terminalWidth);
|
||||
table.colorHeader (Color ("underline"));
|
||||
table.add ("Extension", true);
|
||||
table.add ("Status", true);
|
||||
|
|
|
@ -52,8 +52,10 @@ GapsTable::Builder& GapsTable::Builder::withIntervals (const std::vector <Range>
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
Table GapsTable::Builder::build ()
|
||||
{
|
||||
int terminalWidth = getTerminalWidth ();
|
||||
|
||||
Table table;
|
||||
table.width (1024);
|
||||
table.width (terminalWidth);
|
||||
table.colorHeader (Color ("underline"));
|
||||
table.add ("Wk");
|
||||
table.add ("Date");
|
||||
|
|
|
@ -131,8 +131,10 @@ Table SummaryTable::Builder::build ()
|
|||
const auto duration_col_index = 3 + start_col_offset;
|
||||
const auto total_col_index = 4 + start_col_offset;
|
||||
|
||||
int terminalWidth = getTerminalWidth ();
|
||||
|
||||
Table table;
|
||||
table.width (1024);
|
||||
table.width (terminalWidth);
|
||||
table.colorHeader (Color ("underline"));
|
||||
|
||||
if (_show_weeks)
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <TagsTable.h>
|
||||
#include <timew.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
TagsTable::Builder TagsTable::builder ()
|
||||
|
@ -42,8 +43,10 @@ TagsTable::Builder& TagsTable::Builder::withTagDescriptions (std::vector <TagDes
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
Table TagsTable::Builder::build ()
|
||||
{
|
||||
int terminalWidth = getTerminalWidth ();
|
||||
|
||||
Table table;
|
||||
table.width (1024);
|
||||
table.width (terminalWidth);
|
||||
table.colorHeader (Color ("underline"));
|
||||
table.add ("Tag");
|
||||
table.add ("Description");
|
||||
|
|
|
@ -27,12 +27,15 @@
|
|||
#include <Datetime.h>
|
||||
#include <Duration.h>
|
||||
#include <IntervalFactory.h>
|
||||
#include <Table.h>
|
||||
#include <format.h>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <sys/ioctl.h>
|
||||
#include <timew.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -512,3 +515,20 @@ std::string minimalDelta (const Datetime& left, const Datetime& right)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int getTerminalWidth ()
|
||||
{
|
||||
int terminalWidth;
|
||||
#ifdef TIOCGSIZE
|
||||
struct ttysize ts{};
|
||||
ioctl (STDIN_FILENO, TIOCGSIZE, &ts);
|
||||
terminalWidth = ts.ts_cols;
|
||||
#elif defined(TIOCGWINSZ)
|
||||
struct winsize ts {};
|
||||
ioctl(STDIN_FILENO, TIOCGWINSZ, &ts);
|
||||
terminalWidth = ts.ws_col;
|
||||
#endif
|
||||
|
||||
return terminalWidth > 0 ? terminalWidth : 80;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -82,6 +82,7 @@ int quantizeToNMinutes (int, int);
|
|||
|
||||
bool findHint (const CLI&, const std::string&);
|
||||
std::string minimalDelta (const Datetime&, const Datetime&);
|
||||
int getTerminalWidth () ;
|
||||
|
||||
// log.cpp
|
||||
void enableDebugMode (bool);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue