1. Steve Losh
  2. lanterna

Commits

mabe02  committed 97e99eb

Show memory usage option

  • Participants
  • Parent commits acd99cc
  • Branches default

Comments (0)

Files changed (1)

File src/org/lantern/gui/GUIScreen.java

View file
     private final LinkedList<WindowPlacement> windowStack;
     private final Queue<Action> actionToRunInEventThread;
     private String title;
+    private boolean showMemoryUsage;
     private Theme guiTheme;
     private boolean needsRefresh;
     private Thread eventThread;
     public GUIScreen(final Screen screen)
     {
         this.title = "";
+        this.showMemoryUsage = false;
         this.screen = screen;
         this.guiTheme = Theme.getDefaultTheme();
         this.windowStack = new LinkedList<WindowPlacement>();
         //Write the title
         textGraphics.drawString(3, 0, title);
 
+        //Write memory usage
+        if(showMemoryUsage)
+            drawMemoryUsage(textGraphics);
+
         //Go through the windows
         for(WindowPlacement windowPlacement: windowStack) {
             if(hasSoloWindowAbove(windowPlacement))
         return eventThread == Thread.currentThread();
     }
 
+    public void setShowMemoryUsage(boolean showMemoryUsage)
+    {
+        this.showMemoryUsage = showMemoryUsage;
+    }
+
+    public boolean isShowingMemoryUsage()
+    {
+        return showMemoryUsage;
+    }
+
     public enum Position
     {
         OVERLAPPING,
         return false;
     }
 
+    private void drawMemoryUsage(TextGraphics textGraphics)
+    {
+        Runtime runtime = Runtime.getRuntime();
+        long freeMemory = runtime.freeMemory();
+        long totalMemory = runtime.totalMemory();
+        long usedMemory = totalMemory - freeMemory;
+
+        usedMemory /= (1024 * 1024);
+        totalMemory /= (1024 * 1024);
+
+        String memUsageString = "Memory usage: " + usedMemory + " MB of " + totalMemory + " MB";
+        textGraphics.drawString(screen.getTerminalSize().getColumns() - memUsageString.length() - 1,
+                screen.getTerminalSize().getRows() - 1, memUsageString);
+    }
+
     private class WindowPlacement
     {
         private Window window;