foxygit / doom Log in
commit 9e165649eb624ece3a0509841016d5e5c3eb2ddf
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Feb 9 22:31:02 2008 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Feb 9 22:31:02 2008 +0000

    Fix up the R_Main startup progress dots. If stdout is a file, don't
    display the surrounding box.

    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 1069
---
 src/i_system.c | 15 +++++++++++++++
 src/i_system.h |  3 +++
 src/r_data.c   | 21 ++++++++++++++-------
 3 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/src/i_system.c b/src/i_system.c
index 7a01362f..5273a2f9 100644
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -99,6 +99,21 @@ byte *I_ZoneBase (int *size)
     return zonemem;
 }

+//
+// I_ConsoleStdout
+//
+// Returns true if stdout is a real console, false if it is a file
+//
+
+boolean I_ConsoleStdout(void)
+{
+#ifdef _WIN32
+    // SDL "helpfully" always redirects stdout to a file.
+    return 0;
+#else
+    return isatty(fileno(stdout));
+#endif
+}

 //
 // I_Init
diff --git a/src/i_system.h b/src/i_system.h
index 71729357..a5e06a50 100644
--- a/src/i_system.h
+++ b/src/i_system.h
@@ -41,6 +41,8 @@ void I_Init (void);
 // for the zone management.
 byte*	I_ZoneBase (int *size);

+boolean I_ConsoleStdout(void);
+

 // Called by D_DoomLoop,
 // called before processing any tics in a frame
@@ -86,3 +88,4 @@ void I_Error (char *error, ...);


 #endif
+
diff --git a/src/r_data.c b/src/r_data.c
index 0f792d8e..2b11d82c 100644
--- a/src/r_data.c
+++ b/src/r_data.c
@@ -529,13 +529,20 @@ void R_InitTextures (void)
     temp1 = W_GetNumForName (DEH_String("S_START"));  // P_???????
     temp2 = W_GetNumForName (DEH_String("S_END")) - 1;
     temp3 = ((temp2-temp1+63)/64) + ((numtextures+63)/64);
-    printf("[");
-    for (i = 0; i < temp3; i++)
-	printf(" ");
-    printf("         ]");
-    for (i = 0; i < temp3; i++)
-	printf("\x8");
-    printf("\x8\x8\x8\x8\x8\x8\x8\x8\x8\x8");
+
+    // If stdout is a real console, use the classic vanilla "filling
+    // up the box" effect, which uses backspace to "step back" inside
+    // the box.  If stdout is a file, don't draw the box.
+
+    if (I_ConsoleStdout())
+    {
+        printf("[");
+        for (i = 0; i < temp3 + 9; i++)
+            printf(" ");
+        printf("]");
+        for (i = 0; i < temp3 + 10; i++)
+            printf("\b");
+    }

     for (i=0 ; i<numtextures ; i++, directory++)
     {