Exemple #1
0
 public ProgressWriter(long expectedTargetValue, OutputDevice output)
 {
     _expectedTargetValue = expectedTargetValue;
     _out = output;
     _progressDots = 0;
     _startTime = DateTime.Now;
     _lastEtaUpdate = DateTime.MinValue;
     _etaWriter = new CancelWriter(_out);
     ScreenWidth = DefaultScreenWidth;
 }
Exemple #2
0
 public static void PrintFraction(long execTime, long number, OutputDevice output)
 {
     if (number == 0) {
         output.Write(" -- ");
         return;
     }
     long milli = execTime / number;
     long micro = (execTime - number * milli) * 1000 / number;
     PrintTime(milli, micro, output);
 }
Exemple #3
0
 protected ShellApplication()
 {
     output = new ConsoleOutputDevice(System.Console.Out, true);
     message = new ConsoleOutputDevice(System.Console.Error, false);
     input = new ConsoleInputDevice();
     dispatcher = new CommandDispatcher(this);
     if (this is ISettingsHandler)
         settings = new ApplicationSettings(this);
     if (this is IPropertyHandler)
         properties = new PropertyRegistry(this as IPropertyHandler);
     if (this is IPluginHandler)
         plugins = new ApplicationPlugins(this);
     interruptHandler = new ApplicationInterruptionHandler(this);
 }
Exemple #4
0
        public TableRenderer(ColumnDesign[] columns, OutputDevice output, string separator, bool enableHeader, bool enableFooter)
        {
            this.columns = columns;
            this.output = output;
            this.enableHeader = enableHeader;
            this.enableFooter = enableFooter;

            // we cache the rows in order to dynamically determine the
            // output width of each column.
            cacheRows = new ArrayList(MaxCacheElements);
            alreadyFlushed = false;
            writtenRows = 0;
            colSeparator = " " + separator;
            separatorWidth = separator.Length;
        }
Exemple #5
0
 public CancelWriter(OutputDevice output)
 {
     _out = output;
     _doWrite = _out.IsTerminal;
     _writtenString = null;
 }
Exemple #6
0
        /** print time to output device */
        public static void PrintTime(long execTimeInMs, long usec, OutputDevice output)
        {
            long totalTime = execTimeInMs;

            bool hourPrinted   = false;
            bool minutePrinted = false;

            if (execTimeInMs > HourMillis)
            {
                output.Write(Convert.ToString(execTimeInMs / HourMillis));
                output.Write("h ");
                execTimeInMs %= HourMillis;
                hourPrinted   = true;
            }

            if (hourPrinted || execTimeInMs > MinuteMillis)
            {
                long minute = execTimeInMs / 60000;
                if (hourPrinted && minute < 10)
                {
                    output.Write("0");                     // need padding.
                }
                output.Write(minute.ToString());
                output.Write("m ");
                execTimeInMs %= MinuteMillis;
                minutePrinted = true;
            }

            if (minutePrinted || execTimeInMs >= SecondMillis)
            {
                long seconds = execTimeInMs / SecondMillis;
                if (minutePrinted && seconds < 10)
                {
                    output.Write("0");                     // need padding.
                }
                output.Write(seconds.ToString());
                output.Write(".");
                execTimeInMs %= SecondMillis;
                // milliseconds
                if (execTimeInMs < 100)
                {
                    output.Write("0");
                }
                if (execTimeInMs < 10)
                {
                    output.Write("0");
                }
                output.Write(execTimeInMs.ToString());
            }
            else if (execTimeInMs > 0)
            {
                output.Write(execTimeInMs.ToString());
            }

            if (usec > 0)
            {
                if (totalTime > 0)                    // need delimiter and padding.
                {
                    output.Write(".");
                    if (usec < 100)
                    {
                        output.Write("0");
                    }
                    if (usec < 10)
                    {
                        output.Write("0");
                    }
                }
                output.Write(usec.ToString());
            }
            else if (execTimeInMs == 0)
            {
                output.Write("0 ");
            }

            if (totalTime > MinuteMillis)
            {
                output.Write("s");
            }
            else if (totalTime >= SecondMillis)
            {
                output.Write(" ");
            }
            else if (totalTime > 0 && totalTime < SecondMillis)
            {
                output.Write(" m");
            }
            else if (totalTime == 0 && usec > 0)
            {
                output.Write(" µ");
            }
            else
            {
                output.Write("sec");
            }
        }
Exemple #7
0
 /** print time to output device */
 public static void PrintTime(long execTimeInMs, OutputDevice output)
 {
     PrintTime(execTimeInMs, 0, output);
 }
Exemple #8
0
 public CancelWriter(OutputDevice output)
 {
     _out           = output;
     _doWrite       = _out.IsTerminal;
     _writtenString = null;
 }
Exemple #9
0
        public void SetPrompt(string text)
        {
            prompt = text;
            //			StringBuilder tmp = new StringBuilder();
            //			int emptyLength = prompt.Length;
            //			for (int i = emptyLength; i > 0; --i) {
            //				tmp.Append(' ');
            //			}
            //			emptyPrompt = tmp.ToString();

            if (output == null)
                output = new ConsoleOutputDevice(System.Console.Out, true);
            if (message == null)
                message = new ConsoleOutputDevice(System.Console.Error, false);
            if (input == null)
                input = new ConsoleInputDevice();

            if (output is ConsoleOutputDevice)
                (output as ConsoleOutputDevice).Prompt = prompt;
            if (input is ConsoleInputDevice)
                (input as ConsoleInputDevice).Prompt = prompt;
        }
Exemple #10
0
        public void SetOutDevice(OutputDevice device)
        {
            if (device == null)
                throw new ArgumentNullException("device");
            if (device is ConsoleOutputDevice)
                (device as ConsoleOutputDevice).Prompt = prompt;

            output = device;
        }
Exemple #11
0
        public void SetErrorDevice(OutputDevice device)
        {
            if (device == null)
                throw new ArgumentNullException("device");

            message = device;
        }
Exemple #12
0
 public TableRenderer(ColumnDesign[] columns, OutputDevice output)
     : this(columns, output, "|", true, true)
 {
 }
Exemple #13
0
        /** print time to output device */
        public static void PrintTime(long execTimeInMs, long usec, OutputDevice output)
        {
            long totalTime = execTimeInMs;

            bool hourPrinted = false;
            bool minutePrinted = false;

            if (execTimeInMs > HourMillis) {
                output.Write(Convert.ToString(execTimeInMs / HourMillis));
                output.Write("h ");
                execTimeInMs %= HourMillis;
                hourPrinted = true;
            }

            if (hourPrinted || execTimeInMs > MinuteMillis) {
                long minute = execTimeInMs / 60000;
                if (hourPrinted && minute < 10) {
                    output.Write("0"); // need padding.
                }
                output.Write(minute.ToString());
                output.Write("m ");
                execTimeInMs %= MinuteMillis;
                minutePrinted = true;
            }

            if (minutePrinted || execTimeInMs >= SecondMillis) {
                long seconds = execTimeInMs / SecondMillis;
                if (minutePrinted && seconds < 10) {
                    output.Write("0"); // need padding.
                }
                output.Write(seconds.ToString());
                output.Write(".");
                execTimeInMs %= SecondMillis;
                // milliseconds
                if (execTimeInMs < 100)
                    output.Write("0");
                if (execTimeInMs < 10)
                    output.Write("0");
                output.Write(execTimeInMs.ToString());
            } else if (execTimeInMs > 0) {
                output.Write(execTimeInMs.ToString());
            }

            if (usec > 0) {
                if (totalTime > 0) {  // need delimiter and padding.
                    output.Write(".");
                    if (usec < 100)
                        output.Write("0");
                    if (usec < 10)
                        output.Write("0");
                }
                output.Write(usec.ToString());
            } else if (execTimeInMs == 0) {
                output.Write("0 ");
            }

            if (totalTime > MinuteMillis) {
                output.Write("s");
            } else if (totalTime >= SecondMillis)
                output.Write(" ");
            else if (totalTime > 0 && totalTime < SecondMillis)
                output.Write(" m");
            else if (totalTime == 0 && usec > 0)
                output.Write(" µ");
            else
                output.Write("sec");
        }
Exemple #14
0
 /** print time to output device */
 public static void PrintTime(long execTimeInMs, OutputDevice output)
 {
     PrintTime(execTimeInMs, 0, output);
 }
Exemple #15
0
 public TableRenderer(ColumnDesign[] columns, OutputDevice output)
     : this(columns, output, "|", true, true)
 {
 }