Skip to content

Commit

Permalink
Merge pull request #3 from lmstudio-ai/fix-nontty-clearline
Browse files Browse the repository at this point in the history
Fix non-TTY
  • Loading branch information
ryan-the-crayon committed May 2, 2024
2 parents b797be6 + 5930e15 commit b7e3b03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/ProgressBar.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { clearLine, cursorTo } from "readline";

const spinnerFrames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];

export class ProgressBar {
Expand All @@ -18,8 +20,8 @@ export class ProgressBar {
throw new Error("ProgressBar already stopped");
}
this.stopped = true;
process.stdout.clearLine(0);
process.stdout.cursorTo(0);
clearLine(process.stdout, 0);
cursorTo(process.stdout, 0);
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
Expand Down
12 changes: 6 additions & 6 deletions src/createClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import chalk from "chalk";
import { flag } from "cmd-ts";
import inquirer from "inquirer";
import { platform } from "os";
import { clearLine, moveCursor } from "readline";
import { getCliPref } from "./cliPref";
import { type LogLevelArgs, type LogLevelMap } from "./logLevel";
import {
Expand Down Expand Up @@ -125,28 +126,28 @@ function createSelfDeletingLogger(logger: SimpleLogger, levelMap: LogLevelMap) {
{
debug: levelMap.debug
? (...messages) => {
process.stderr.clearLine(0);
clearLine(process.stderr, 0);
logger.debug(...messages);
}
: () => {},
info: levelMap.info
? (...messages) => {
process.stderr.clearLine(0);
clearLine(process.stderr, 0);
logger.info(...messages);
if (!levelMap.debug) {
process.stderr.moveCursor(0, -1);
moveCursor(process.stderr, 0, -1);
}
}
: () => {},
warn: levelMap.warn
? (...messages) => {
process.stderr.clearLine(0);
clearLine(process.stderr, 0);
logger.warn(...messages);
}
: () => {},
error: levelMap.error
? (...messages) => {
process.stderr.clearLine(0);
clearLine(process.stderr, 0);
logger.error(...messages);
}
: () => {},
Expand Down Expand Up @@ -180,7 +181,6 @@ export async function createClient(
}
const baseUrl = `ws:https://127.0.0.1:${port}`;
logger.debug(`Connecting to server with baseUrl ${port}`);
process.stderr.clearLine(0);
return new LMStudioClient({
baseUrl,
logger,
Expand Down

0 comments on commit b7e3b03

Please sign in to comment.