144d93782SGreg Clayton //===-- CommandObjectGUI.cpp ------------------------------------*- C++ -*-===//
244d93782SGreg Clayton //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
644d93782SGreg Clayton //
744d93782SGreg Clayton //===----------------------------------------------------------------------===//
844d93782SGreg Clayton 
944d93782SGreg Clayton #include "CommandObjectGUI.h"
1044d93782SGreg Clayton 
1144d93782SGreg Clayton #include "lldb/Interpreter/CommandInterpreter.h"
1244d93782SGreg Clayton #include "lldb/Interpreter/CommandReturnObject.h"
13b9c1b51eSKate Stone #include "lldb/lldb-private.h"
1444d93782SGreg Clayton 
1544d93782SGreg Clayton using namespace lldb;
1644d93782SGreg Clayton using namespace lldb_private;
1744d93782SGreg Clayton 
1844d93782SGreg Clayton // CommandObjectGUI
1944d93782SGreg Clayton 
20b9c1b51eSKate Stone CommandObjectGUI::CommandObjectGUI(CommandInterpreter &interpreter)
21b9c1b51eSKate Stone     : CommandObjectParsed(interpreter, "gui",
22b9c1b51eSKate Stone                           "Switch into the curses based GUI mode.", "gui") {}
2344d93782SGreg Clayton 
24b9c1b51eSKate Stone CommandObjectGUI::~CommandObjectGUI() {}
2544d93782SGreg Clayton 
26b9c1b51eSKate Stone bool CommandObjectGUI::DoExecute(Args &args, CommandReturnObject &result) {
27914b8d98SDeepak Panickal #ifndef LLDB_DISABLE_CURSES
28b9c1b51eSKate Stone   if (args.GetArgumentCount() == 0) {
2957179860SJonas Devlieghere     Debugger &debugger = GetDebugger();
30456f2712SGreg Clayton 
317ca15ba7SLawrence D'Anna     File &input = debugger.GetInputFile();
32*609010d0SLawrence D'Anna     File &output = debugger.GetOutputFile();
33*609010d0SLawrence D'Anna     if (input.GetStream() && output.GetStream() && input.GetIsRealTerminal() &&
34*609010d0SLawrence D'Anna         input.GetIsInteractive()) {
3544d93782SGreg Clayton       IOHandlerSP io_handler_sp(new IOHandlerCursesGUI(debugger));
3644d93782SGreg Clayton       if (io_handler_sp)
3744d93782SGreg Clayton         debugger.PushIOHandler(io_handler_sp);
3844d93782SGreg Clayton       result.SetStatus(eReturnStatusSuccessFinishResult);
39b9c1b51eSKate Stone     } else {
40456f2712SGreg Clayton       result.AppendError("the gui command requires an interactive terminal.");
41456f2712SGreg Clayton       result.SetStatus(eReturnStatusFailed);
42456f2712SGreg Clayton     }
43b9c1b51eSKate Stone   } else {
4444d93782SGreg Clayton     result.AppendError("the gui command takes no arguments.");
4544d93782SGreg Clayton     result.SetStatus(eReturnStatusFailed);
4644d93782SGreg Clayton   }
4744d93782SGreg Clayton   return true;
48914b8d98SDeepak Panickal #else
49914b8d98SDeepak Panickal   result.AppendError("lldb was not build with gui support");
50914b8d98SDeepak Panickal   return false;
51914b8d98SDeepak Panickal #endif
5244d93782SGreg Clayton }
53