mirror of
https://git.proxmox.com/git/pve-common
synced 2025-07-27 10:01:38 +00:00
PVE::CLIFormatter::query_terminal_options - new helper
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
parent
43b104c416
commit
4ac8500023
@ -2,11 +2,30 @@ package PVE::CLIFormatter;
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use I18N::Langinfo;
|
||||||
|
|
||||||
use PVE::JSONSchema;
|
use PVE::JSONSchema;
|
||||||
|
use PVE::PTY;
|
||||||
use JSON;
|
use JSON;
|
||||||
use utf8;
|
use utf8;
|
||||||
use Encode;
|
use Encode;
|
||||||
|
|
||||||
|
sub query_terminal_options {
|
||||||
|
my ($options) = @_;
|
||||||
|
|
||||||
|
$options //= {};
|
||||||
|
|
||||||
|
if (-t STDOUT) {
|
||||||
|
($options->{columns}) = PVE::PTY::tcgetsize(*STDOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
$options->{encoding} = I18N::Langinfo::langinfo(I18N::Langinfo::CODESET());
|
||||||
|
|
||||||
|
$options->{utf8} = 1 if $options->{encoding} eq 'UTF-8';
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
sub println_max {
|
sub println_max {
|
||||||
my ($text, $encoding, $max) = @_;
|
my ($text, $encoding, $max) = @_;
|
||||||
|
|
||||||
@ -217,8 +236,11 @@ sub print_api_list {
|
|||||||
sub print_api_result {
|
sub print_api_result {
|
||||||
my ($format, $data, $result_schema, $props_to_print, $options) = @_;
|
my ($format, $data, $result_schema, $props_to_print, $options) = @_;
|
||||||
|
|
||||||
$options //= {};
|
if (!defined($options)) {
|
||||||
$options = { %$options }; # copy
|
$options = query_terminal_options({});
|
||||||
|
} else {
|
||||||
|
$options = { %$options }; # copy
|
||||||
|
}
|
||||||
|
|
||||||
return if $result_schema->{type} eq 'null';
|
return if $result_schema->{type} eq 'null';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user