3232#include  " SpecUtils/Filesystem.h" 
3333#include  " cambio/CommandLineUtil.h" 
3434
35+ 
36+ //  Some includes to get terminal width
37+ #if  defined(__APPLE__) || defined(linux) || defined(unix) || defined(__unix) || defined(__unix__)
38+ #include  < sys/ioctl.h> 
39+ #include  < unistd.h> 
40+ #elif  defined(_WIN32)
41+ #define  NOMINMAX 
42+ #define  WIN32_LEAN_AND_MEAN  1 
43+ #include  < Windows.h> 
44+ #endif 
45+ 
46+ 
3547using  namespace  std ; 
3648namespace  po  =  boost::program_options;
3749using  SpecUtils::convert_from_utf8_to_utf16;
@@ -64,6 +76,7 @@ namespace {
6476  }
6577#endif 
6678
79+ 
6780  bool  html_page_header ( std::ostream &ostr, const  std::string &title )
6881  {
6982    const  char  *endline = " \r\n " 
@@ -464,6 +477,35 @@ namespace
464477      }
465478    }// if( print_debug )
466479  }// void normalize_det_name_to_n42( SpecUtils::SpecFile &info )
480+ 
481+ 
482+ #if  defined(__APPLE__) || defined(unix) || defined(__unix) || defined(__unix__)
483+ unsigned  terminal_width ()
484+ {
485+   winsize ws = {};
486+   if  (ioctl (STDOUT_FILENO, TIOCGWINSZ, &ws) <= -1 )
487+     return  80 ;
488+   unsigned  w = (ws.ws_col );
489+   return  std::max ( 40u , w );
490+ }
491+ #elif  defined(_WIN32)
492+ unsigned  terminal_width ()
493+ {
494+   HANDLE handle = GetStdHandle (STD_OUTPUT_HANDLE);
495+   if ( handle == INVALID_HANDLE_VALUE )
496+     return  80 ;
497+   
498+   CONSOLE_SCREEN_BUFFER_INFO info;
499+   if ( !GetConsoleScreenBufferInfo (handle, &info) )
500+     return  80 ;
501+   
502+   return  unsigned (info.srWindow .Right  - info.srWindow .Left );
503+ }
504+ #else 
505+ static_assert ( 0 , " Not unix and not win32?  Unsupported getting terminal width" 
506+ #endif 
507+ 
508+ 
467509}// namespace
468510
469511namespace  CommandLineUtil 
@@ -518,8 +560,11 @@ int run_command_util( const int argc, char *argv[] )
518560  string template_file;
519561  bool  strip_template_blocks;
520562#endif 
521- 
522-   po::options_description cl_desc (" Allowed options" 
563+   
564+   unsigned  term_width = terminal_width ();
565+   unsigned  min_description_length = ((term_width < 80u ) ? term_width/2u  : 40u );
566+   
567+   po::options_description cl_desc (" Allowed options" 
523568  cl_desc.add_options ()
524569    (" help,h" " produce this help message" 
525570    (" about,a" " produce the about message" 
@@ -532,8 +577,8 @@ int run_command_util( const int argc, char *argv[] )
532577    (" format,f" 
533578              " Format of output spectrum file.  Must be specified when there" 
534579              "  are multiple input files, or if the output name for a single" 
535-               "  spectrum file is ambigous .  For a single file, if this option" 
536-               "  is not specified, the output names file extention  will be used" 
580+               "  spectrum file is ambiguous .  For a single file, if this option" 
581+               "  is not specified, the output names file extension  will be used" 
537582              "  to guess output format desired.\n " 
538583              " Possible values are: \t TXT, CSV, PCF, XML (2006 N42 format)," 
539584              "  N42 (defaults to 2012 variant), 2012N42, 2006N42," 
@@ -699,7 +744,7 @@ int run_command_util( const int argc, char *argv[] )
699744"                                                                                \n " 
700745" Please email wcjohns@sandia.gov AND cambio@sandia.gov with bug reports,        \n " 
701746" suggestions, requests, or new file formats.                                    \n " 
702- " Please visit https://hekili.ca.sandia.gov/CAMBIO/  for updates and additional   \n " 
747+ " Please visit https://github.com/sandialabs/cambio  for updates and additional   \n " 
703748" information.\n " 
704749" \n " 
705750" Copyright (C) 2014 Sandia National Laboratories, org 08126\n " 
@@ -954,7 +999,7 @@ int run_command_util( const int argc, char *argv[] )
954999  if ( inputfiles.size () > 1  && !SpecUtils::is_directory (outputname) )
9551000  {
9561001    cerr << " You must specify an output directory when there are mutliple input" 
957-          << "  files" 
1002+          << "  files  -- SpecUtils::is_directory(' "  << outputname <<  " ')= "  <<  SpecUtils::is_directory (outputname)  << endl;
9581003    return  3 ;
9591004  }// if( mutliple input files, and not a output directory )
9601005
0 commit comments