Skip to content

Commit

Permalink
fix: set progress bar width base on terminal width (#1713)
Browse files Browse the repository at this point in the history
* fix: set progress bar width base on terminal width

* chore: CI

* fix: CI

---------

Co-authored-by: vansangpfiev <[email protected]>
  • Loading branch information
vansangpfiev and sangjanai authored Nov 22, 2024
1 parent 16e7c00 commit 8db7e9c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/cortex-cpp-quality-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
cd engine
echo "huggingFaceToken: ${{ secrets.HUGGINGFACE_TOKEN_READ }}" > ~/.cortexrc
echo "gitHubToken: ${{ secrets.PAT_SERVICE_ACCOUNT }}" >> ~/.cortexrc
./build/cortex
# ./build/cortex
cat ~/.cortexrc
- name: Run unit tests
Expand All @@ -115,10 +115,10 @@ jobs:
- name: Run setup config
run: |
cd engine
echo "huggingFaceToken: ${{ secrets.HUGGINGFACE_TOKEN_READ }}" > ~/.cortexrc
echo "apiServerPort: 3928" > ~/.cortexrc
echo "huggingFaceToken: ${{ secrets.HUGGINGFACE_TOKEN_READ }}" >> ~/.cortexrc
echo "gitHubToken: ${{ secrets.PAT_SERVICE_ACCOUNT }}" >> ~/.cortexrc
echo "apiServerPort: 3928" >> ~/.cortexrc
./build/cortex
# ./build/cortex
cat ~/.cortexrc
- name: Run e2e tests
Expand Down
20 changes: 19 additions & 1 deletion engine/cli/utils/download_progress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "utils/format_utils.h"
#include "utils/json_helper.h"
#include "utils/logging_utils.h"
#if !defined(WIN32) && !defined(WIN64)
#include <sys/ioctl.h>
#include <unistd.h>
#endif

namespace {
std::string Repo2Engine(const std::string& r) {
Expand All @@ -20,6 +24,20 @@ std::string Repo2Engine(const std::string& r) {
}
return r;
};

int GetColumns() {
#if defined(WIN32) || defined(WIN64)
CONSOLE_SCREEN_BUFFER_INFO csbi;
int columns;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
return columns;
#else
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
return w.ws_col;
#endif
}
} // namespace
bool DownloadProgress::Connect(const std::string& host, int port) {
if (ws_) {
Expand Down Expand Up @@ -97,7 +115,7 @@ bool DownloadProgress::Handle(
items[i.id] = std::pair(
idx,
std::make_unique<indicators::ProgressBar>(
indicators::option::BarWidth{50},
indicators::option::BarWidth{GetColumns() / 6},
indicators::option::Start{"["}, indicators::option::Fill{"="},
indicators::option::Lead{">"}, indicators::option::End{"]"},
indicators::option::PrefixText{pad_string(Repo2Engine(i.id))},
Expand Down
3 changes: 3 additions & 0 deletions engine/e2e-test/test_api_engine_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class TestApiEngineList:
@pytest.fixture(autouse=True)
def setup_and_teardown(self):
# Setup
# Not sure why but on macOS amd, the first start server timeouts with CI
start_server()
stop_server()
success = start_server()
if not success:
raise Exception("Failed to start server")
Expand Down

0 comments on commit 8db7e9c

Please sign in to comment.