Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set progress bar width base on terminal width #1713

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading