src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/Status.java
changeset 58903 eeb1c0da2126
parent 52938 5ff7480c9e28
equal deleted inserted replaced
58902:197238c30630 58903:eeb1c0da2126
     2  * Copyright (c) 2002-2018, the original author or authors.
     2  * Copyright (c) 2002-2018, the original author or authors.
     3  *
     3  *
     4  * This software is distributable under the BSD license. See the terms of the
     4  * This software is distributable under the BSD license. See the terms of the
     5  * BSD license in the documentation provided with this software.
     5  * BSD license in the documentation provided with this software.
     6  *
     6  *
     7  * http://www.opensource.org/licenses/bsd-license.php
     7  * https://opensource.org/licenses/BSD-3-Clause
     8  */
     8  */
     9 package jdk.internal.org.jline.utils;
     9 package jdk.internal.org.jline.utils;
    10 
    10 
    11 import java.util.Objects;
    11 import java.util.Objects;
    12 import java.util.Collections;
    12 import java.util.Collections;
    22 public class Status {
    22 public class Status {
    23 
    23 
    24     protected final AbstractTerminal terminal;
    24     protected final AbstractTerminal terminal;
    25     protected final boolean supported;
    25     protected final boolean supported;
    26     protected List<AttributedString> oldLines = Collections.emptyList();
    26     protected List<AttributedString> oldLines = Collections.emptyList();
       
    27     protected List<AttributedString> linesToRestore = Collections.emptyList();
    27     protected int rows;
    28     protected int rows;
    28     protected int columns;
    29     protected int columns;
    29     protected boolean force;
    30     protected boolean force;
       
    31     protected boolean suspended = false;
    30 
    32 
    31     public static Status getStatus(Terminal terminal) {
    33     public static Status getStatus(Terminal terminal) {
    32         return getStatus(terminal, true);
    34         return getStatus(terminal, true);
    33     }
    35     }
    34 
    36 
    59 
    61 
    60     public void reset() {
    62     public void reset() {
    61         this.force = true;
    63         this.force = true;
    62     }
    64     }
    63 
    65 
       
    66     public void hardReset() {
       
    67         if (suspended) {
       
    68             return;
       
    69         }
       
    70         List<AttributedString> lines = new ArrayList<>(oldLines);
       
    71         update(null);
       
    72         update(lines);
       
    73     }
       
    74 
    64     public void redraw() {
    75     public void redraw() {
       
    76         if (suspended) {
       
    77             return;
       
    78         }
    65         update(oldLines);
    79         update(oldLines);
    66     }
    80     }
    67 
    81 
    68     public void update(List<AttributedString> lines) {
    82     public void update(List<AttributedString> lines) {
       
    83         if (!supported) {
       
    84             return;
       
    85         }
    69         if (lines == null) {
    86         if (lines == null) {
    70             lines = Collections.emptyList();
    87             lines = Collections.emptyList();
    71         }
    88         }
    72         if (!supported || (oldLines.equals(lines) && !force)) {
    89         if (suspended) {
       
    90             linesToRestore = new ArrayList<>(lines);
       
    91             return;
       
    92         }
       
    93         if (oldLines.equals(lines) && !force) {
    73             return;
    94             return;
    74         }
    95         }
    75         int nb = lines.size() - oldLines.size();
    96         int nb = lines.size() - oldLines.size();
    76         if (nb > 0) {
    97         if (nb > 0) {
    77             for (int i = 0; i < nb; i++) {
    98             for (int i = 0; i < nb; i++) {
    80             for (int i = 0; i < nb; i++) {
   101             for (int i = 0; i < nb; i++) {
    81                 terminal.puts(Capability.cursor_up);
   102                 terminal.puts(Capability.cursor_up);
    82             }
   103             }
    83         }
   104         }
    84         terminal.puts(Capability.save_cursor);
   105         terminal.puts(Capability.save_cursor);
       
   106         terminal.puts(Capability.cursor_address, rows - lines.size(), 0);
    85         terminal.puts(Capability.clr_eos);
   107         terminal.puts(Capability.clr_eos);
    86         for (int i = 0; i < lines.size(); i++) {
   108         for (int i = 0; i < lines.size(); i++) {
    87             terminal.puts(Capability.cursor_address, rows - lines.size() + i, 0);
   109             terminal.puts(Capability.cursor_address, rows - lines.size() + i, 0);
    88             terminal.writer().write(lines.get(i).columnSubSequence(0, columns).toAnsi(terminal));
   110             lines.get(i).columnSubSequence(0, columns).print(terminal);
    89         }
   111         }
    90         terminal.puts(Capability.change_scroll_region, 0, rows - 1 - lines.size());
   112         terminal.puts(Capability.change_scroll_region, 0, rows - 1 - lines.size());
    91         terminal.puts(Capability.restore_cursor);
   113         terminal.puts(Capability.restore_cursor);
    92         terminal.flush();
   114         terminal.flush();
    93         oldLines = new ArrayList<>(lines);
   115         oldLines = new ArrayList<>(lines);
    94         force = false;
   116         force = false;
    95     }
   117     }
       
   118 
       
   119     public void suspend() {
       
   120         if (suspended) {
       
   121             return;
       
   122         }
       
   123         linesToRestore = new ArrayList<>(oldLines);
       
   124         update(null);
       
   125         suspended = true;
       
   126     }
       
   127 
       
   128     public void restore() {
       
   129         if (!suspended) {
       
   130             return;
       
   131         }
       
   132         suspended = false;
       
   133         update(linesToRestore);
       
   134         linesToRestore = Collections.emptyList();
       
   135     }
       
   136 
       
   137     public int size() {
       
   138         return oldLines.size();
       
   139     }
       
   140 
    96 }
   141 }