ls tty fix

This commit is contained in:
Murphy 2023-04-28 15:48:55 -04:00
parent 7a1eef1229
commit 4403e7edc2

View file

@ -166,10 +166,13 @@ static char* get_file_color(struct FileInfo* info) {
} }
static void list_files(struct FileInfo* files, int file_len, struct FileListInfo info, struct Flags* flags, const char* dir_path) { static void list_files(struct FileInfo* files, int file_len, struct FileListInfo info, struct Flags* flags, const char* dir_path) {
struct winsize w; struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
if (!isatty(1)) {
flags->one_column = true;
}
char* color; char* color;
const int column_width = info.max_name + 1; const int column_width = info.max_name + 1;
const int row_count = w.ws_col / column_width; const int row_count = w.ws_col / column_width;
@ -371,7 +374,6 @@ COMMAND(ls) {
flags.hide_dot = false; flags.hide_dot = false;
flags.one_column = false; flags.one_column = false;
flags.recurse = false; flags.recurse = false;
int start = 0; int start = 0;
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
if (!prefix("-", argv[i])) break; if (!prefix("-", argv[i])) break;