2 * PROMPT.C - prompt handling.
7 * 14/01/95 (Tim Normal)
10 * 08/08/95 (Matt Rains)
11 * i have cleaned up the source code. changes now bring this source
12 * into guidelines for recommended programming practice.
14 * 01/06/96 (Tim Norman)
15 * added day of the week printing (oops, forgot about that!)
17 * 08/07/96 (Steffan Kaiser)
18 * small changes for speed
20 * 20-Jul-1998 (John P Price <linux-guru@gcfl.net>)
21 * removed redundant day strings. Use ones defined in date.c.
23 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
24 * added config.h include
26 * 28-Jul-1998 (John P Price <linux-guru@gcfl.net>)
27 * moved cmd_prompt from internal.c to here
29 * 09-Dec-1998 (Eric Kohl)
30 * Added help text ("/?").
32 * 14-Dec-1998 (Eric Kohl)
35 * 09-Jan-1999 (Eric Kohl)
36 * Added "$A", "$C" and "$F" option.
37 * Added locale support.
40 * 20-Jan-1999 (Eric Kohl)
41 * Unicode and redirection safe!
43 * 24-Jan-1999 (Eric Kohl)
44 * Fixed Win32 environment handling.
46 * 30-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
47 * Remove all hardcoded strings in En.rc
51 /* The default prompt */
52 static TCHAR DefaultPrompt
[] = _T("$P$G");
55 * Initialize prompt support.
62 * Set the PROMPT environment variable if it doesn't exist already.
63 * You can change the PROMPT environment variable before cmd starts.
65 if (GetEnvironmentVariable(_T("PROMPT"), Buffer
, _countof(Buffer
)) == 0)
66 SetEnvironmentVariable(_T("PROMPT"), DefaultPrompt
);
70 * Print an information line on top of the screen.
72 VOID
PrintInfoLine(VOID
)
74 #define FOREGROUND_WHITE (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
76 HANDLE hOutput
= GetStdHandle(STD_OUTPUT_HANDLE
);
77 CONSOLE_SCREEN_BUFFER_INFO csbi
;
81 PTSTR pszInfoLine
= NULL
;
84 /* Return directly if the output handle is not a console handle */
85 if (!GetConsoleScreenBufferInfo(hOutput
, &csbi
))
88 iInfoLineLen
= LoadString(CMD_ModuleHandle
, STRING_CMD_INFOLINE
, (PTSTR
)&pszInfoLine
, 0);
89 if (!pszInfoLine
|| iInfoLineLen
== 0)
92 /* Display the localized information line */
95 FillConsoleOutputAttribute(hOutput
, BACKGROUND_BLUE
| FOREGROUND_WHITE
,
98 FillConsoleOutputCharacter(hOutput
, _T(' '),
102 WriteConsoleOutputCharacter(hOutput
, pszInfoLine
, iInfoLineLen
,
107 * Print the command-line prompt.
109 VOID
PrintPrompt(VOID
)
113 TCHAR szPath
[MAX_PATH
];
115 if (GetEnvironmentVariable(_T("PROMPT"), szPrompt
, _countof(szPrompt
)))
130 switch (_totupper(*pr
))
145 ConOutPrintf(_T("%s"), GetDateString());
149 ConOutChar(_T('\x1B'));
161 ConOutChar(_T('\x08'));
163 ConOutChar(_T('\x08'));
176 GetCurrentDirectory(_countof(szPath
), szPath
);
177 ConOutChar(szPath
[0]);
183 GetCurrentDirectory(_countof(szPath
), szPath
);
184 ConOutPrintf(_T("%s"), szPath
);
197 ConOutPrintf(_T("%s"), GetTimeString());
205 ConOutChar(_T('\n'));
212 #ifdef FEATURE_DIRECTORY_STACK
216 for (i
= 0; i
< GetDirectoryStackDepth(); i
++)
228 #ifdef INCLUDE_CMD_PROMPT
230 INT
cmd_prompt(LPTSTR param
)
232 if (!_tcsncmp(param
, _T("/?"), 2))
234 ConOutResPaging(TRUE
, STRING_PROMPT_HELP1
);
236 #ifdef FEATURE_DIRECTORY_STACK
237 ConOutResPaging(FALSE
, STRING_PROMPT_HELP2
);
239 ConOutResPaging(FALSE
, STRING_PROMPT_HELP3
);
244 * Set the PROMPT environment variable. If 'param' is NULL or is
245 * an empty string (the user entered "prompt" only), then remove
246 * the environment variable and therefore use the default prompt.
247 * Otherwise, use the new prompt.
249 if (!SetEnvironmentVariable(_T("PROMPT"),
250 (param
&& param
[0] != _T('\0') ? param
: NULL
)))