Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
315f467cc7 | |||
e98122c110 | |||
0c5d5b6339 |
@ -29,7 +29,6 @@ src = [
|
||||
'src/util/process.c',
|
||||
'src/util/strbuf.c',
|
||||
'src/util/str_util.c',
|
||||
'src/util/term.c',
|
||||
'src/util/thread.c',
|
||||
'src/util/tick.c',
|
||||
]
|
||||
@ -190,7 +189,6 @@ if get_option('buildtype') == 'debug'
|
||||
'src/options.c',
|
||||
'src/util/strbuf.c',
|
||||
'src/util/str_util.c',
|
||||
'src/util/term.c',
|
||||
]],
|
||||
['test_clock', [
|
||||
'tests/test_clock.c',
|
||||
|
@ -4,14 +4,15 @@
|
||||
#include <getopt.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "options.h"
|
||||
#include "util/log.h"
|
||||
#include "util/strbuf.h"
|
||||
#include "util/str_util.h"
|
||||
#include "util/term.h"
|
||||
|
||||
#include <termios.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#define STR_IMPL_(x) #x
|
||||
#define STR(x) STR_IMPL_(x)
|
||||
@ -742,16 +743,13 @@ print_shortcut(const struct sc_shortcut *shortcut, unsigned cols) {
|
||||
|
||||
void
|
||||
scrcpy_print_usage(const char *arg0) {
|
||||
#define SC_TERM_COLS_DEFAULT 80
|
||||
unsigned cols;
|
||||
unsigned cols = 80;
|
||||
|
||||
if (!isatty(STDERR_FILENO)) {
|
||||
// Not a tty, use a default value
|
||||
cols = SC_TERM_COLS_DEFAULT;
|
||||
} else {
|
||||
bool ok = sc_term_get_size(NULL, &cols);
|
||||
if (!ok) {
|
||||
cols = SC_TERM_COLS_DEFAULT; // default value
|
||||
struct winsize ws;
|
||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1) {
|
||||
cols = ws.ws_col;
|
||||
if (cols < 20) {
|
||||
cols = 20;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,51 +0,0 @@
|
||||
#include "term.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
bool
|
||||
sc_term_get_size(unsigned *rows, unsigned *cols) {
|
||||
#ifdef _WIN32
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
|
||||
bool ok =
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rows) {
|
||||
assert(csbi.srWindow.Bottom >= csbi.srWindow.Top);
|
||||
*rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
|
||||
}
|
||||
|
||||
if (cols) {
|
||||
assert(csbi.srWindow.Right >= csbi.srWindow.Left);
|
||||
*cols = csbi.srWindow.Right - csbi.srWindow.Left + 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
#else
|
||||
struct winsize ws;
|
||||
int r = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
|
||||
if (r == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rows) {
|
||||
*rows = ws.ws_row;
|
||||
}
|
||||
|
||||
if (cols) {
|
||||
*cols = ws.ws_col;
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
#ifndef SC_TERM_H
|
||||
#define SC_TERM_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool
|
||||
sc_term_get_size(unsigned *rows, unsigned *cols);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user