@@ -8,7 +8,6 @@ use std::{
88} ;
99
1010use clap:: { crate_authors, crate_description, value_parser, Arg , ArgAction , Command } ;
11- use crossterm:: tty:: IsTty ;
1211use owo_colors:: OwoColorize as _;
1312
1413use crate :: {
@@ -51,6 +50,30 @@ pub(crate) struct DisplayOptions {
5150
5251pub ( crate ) const DEFAULT_TERMINAL_WIDTH : usize = 80 ;
5352
53+ #[ cfg( not( target_arch = "wasm32" ) ) ]
54+ fn stdout_is_tty ( ) -> bool {
55+ use crossterm:: tty:: IsTty ;
56+ std:: io:: stdout ( ) . is_tty ( )
57+ }
58+
59+ #[ cfg( target_arch = "wasm32" ) ]
60+ fn stdout_is_tty ( ) -> bool {
61+ false
62+ }
63+
64+ #[ cfg( not( target_arch = "wasm32" ) ) ]
65+ fn terminal_columns ( ) -> Option < usize > {
66+ crossterm:: terminal:: size ( )
67+ . ok ( )
68+ . map ( |( cols, _rows) | cols as usize )
69+ . filter ( |cols| * cols > 0 )
70+ }
71+
72+ #[ cfg( target_arch = "wasm32" ) ]
73+ fn terminal_columns ( ) -> Option < usize > {
74+ None
75+ }
76+
5477impl Default for DisplayOptions {
5578 fn default ( ) -> Self {
5679 Self {
@@ -125,7 +148,7 @@ fn app() -> clap::Command {
125148 ) ) ;
126149
127150 after_help. push_str ( "\n \n See the full manual at " ) ;
128- if std :: io :: stdout ( ) . is_tty ( ) {
151+ if stdout_is_tty ( ) {
129152 // Make the link to the manual clickable in terminals that
130153 // support OSC 8, the ANSI escape code for hyperlinks.
131154 //
@@ -596,6 +619,7 @@ fn common_path_suffix(lhs_path: &Path, rhs_path: &Path) -> Option<String> {
596619}
597620
598621/// Does `path` look like "/tmp/git-blob-abcdef/modified_field.txt"?
622+ #[ cfg( not( target_arch = "wasm32" ) ) ]
599623fn is_git_tmpfile ( path : & Path ) -> bool {
600624 let Ok ( rel_path) = path. strip_prefix ( std:: env:: temp_dir ( ) ) else {
601625 return false ;
@@ -612,6 +636,12 @@ fn is_git_tmpfile(path: &Path) -> bool {
612636 . starts_with ( "git-blob-" )
613637}
614638
639+ #[ cfg( target_arch = "wasm32" ) ]
640+ fn is_git_tmpfile ( _path : & Path ) -> bool {
641+ // WASI environments may not have a writable /tmp; skip special-casing.
642+ false
643+ }
644+
615645fn build_display_path ( lhs_path : & FileArgument , rhs_path : & FileArgument ) -> String {
616646 match ( lhs_path, rhs_path) {
617647 ( FileArgument :: NamedPath ( lhs) , FileArgument :: NamedPath ( rhs) ) => {
@@ -1002,10 +1032,8 @@ pub(crate) fn parse_args() -> Mode {
10021032/// Try to work out the width of the terminal we're on, or fall back
10031033/// to a sensible default value.
10041034fn detect_terminal_width ( ) -> usize {
1005- if let Ok ( ( columns, _rows) ) = crossterm:: terminal:: size ( ) {
1006- if columns > 0 {
1007- return columns. into ( ) ;
1008- }
1035+ if let Some ( columns) = terminal_columns ( ) {
1036+ return columns;
10091037 }
10101038
10111039 // If crossterm couldn't detect the terminal width, use the
@@ -1036,7 +1064,7 @@ pub(crate) fn should_use_color(color_output: ColorOutput) -> bool {
10361064fn detect_color_support ( ) -> bool {
10371065 // TODO: consider following the env parsing logic in git_config_bool
10381066 // in config.c.
1039- std :: io :: stdout ( ) . is_tty ( ) || env:: var ( "GIT_PAGER_IN_USE" ) . is_ok ( )
1067+ stdout_is_tty ( ) || env:: var ( "GIT_PAGER_IN_USE" ) . is_ok ( )
10401068}
10411069
10421070#[ cfg( test) ]
0 commit comments