1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCursesLongMessageForm.cxx,v $
6 Date: $Date: 2006/11/29 22:25:46 $
7 Version: $Revision: 1.16 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "../cmCacheManager.h"
18 #include "../cmSystemTools.h"
20 #include "../cmVersion.h"
21 #include "cmCursesLongMessageForm.h"
22 #include "cmCursesMainForm.h"
24 inline int ctrl(int z
)
29 cmCursesLongMessageForm::cmCursesLongMessageForm(std::vector
<std::string
>
30 const& messages
, const char*
33 // Append all messages into on big string
34 std::vector
<std::string
>::const_iterator it
;
35 for(it
=messages
.begin(); it
!= messages
.end(); it
++)
37 this->Messages
+= (*it
);
38 // Add one blank line after each message
39 this->Messages
+= "\n\n";
46 cmCursesLongMessageForm::~cmCursesLongMessageForm()
50 free_field(this->Fields
[0]);
55 void cmCursesLongMessageForm::UpdateStatusBar()
58 getmaxyx(stdscr
, y
, x
);
60 char bar
[cmCursesMainForm::MAX_WIDTH
];
61 int size
= strlen(this->Title
.c_str());
62 if ( size
>= cmCursesMainForm::MAX_WIDTH
)
64 size
= cmCursesMainForm::MAX_WIDTH
-1;
66 strncpy(bar
, this->Title
.c_str(), size
);
67 for(int i
=size
-1; i
<cmCursesMainForm::MAX_WIDTH
; i
++) bar
[i
] = ' ';
70 if (x
< cmCursesMainForm::MAX_WIDTH
)
76 width
= cmCursesMainForm::MAX_WIDTH
;
81 char version
[cmCursesMainForm::MAX_WIDTH
];
83 sprintf(vertmp
,"CMake Version %d.%d - %s", cmVersion::GetMajorVersion(),
84 cmVersion::GetMinorVersion(),cmVersion::GetReleaseVersion().c_str());
85 int sideSpace
= (width
-strlen(vertmp
));
86 for(int i
=0; i
<sideSpace
; i
++) { version
[i
] = ' '; }
87 sprintf(version
+sideSpace
, "%s", vertmp
);
88 version
[width
] = '\0';
96 pos_form_cursor(this->Form
);
99 void cmCursesLongMessageForm::PrintKeys()
102 getmaxyx(stdscr
, y
, x
);
103 if ( x
< cmCursesMainForm::MIN_WIDTH
||
104 y
< cmCursesMainForm::MIN_HEIGHT
)
109 sprintf(firstLine
, "Press [e] to exit help");
113 pos_form_cursor(this->Form
);
117 void cmCursesLongMessageForm::Render(int, int, int, int)
120 getmaxyx(stdscr
, y
, x
);
124 unpost_form(this->Form
);
125 free_form(this->Form
);
129 const char* msg
= this->Messages
.c_str();
135 free_field(this->Fields
[0]);
139 this->Fields
[0] = new_field(y
-6, x
-2, 1, 1, 0, 0);
141 field_opts_off(this->Fields
[0], O_STATIC
);
143 this->Form
= new_form(this->Fields
);
144 post_form(this->Form
);
147 form_driver(this->Form
, REQ_BEG_FIELD
);
148 while(msg
[i
] != '\0' && i
< 60000)
150 if (msg
[i
] == '\n' && msg
[i
+1] != '\0')
152 form_driver(this->Form
, REQ_NEW_LINE
);
156 form_driver(this->Form
, msg
[i
]);
160 form_driver(this->Form
, REQ_BEG_FIELD
);
162 this->UpdateStatusBar();
169 void cmCursesLongMessageForm::HandleInput()
176 char debugMessage
[128];
182 sprintf(debugMessage
, "Message widget handling input, key: %d", key
);
183 cmCursesForm::LogMessage(debugMessage
);
186 if ( key
== 'o' || key
== 'e' )
190 else if ( key
== KEY_DOWN
|| key
== ctrl('n') )
192 form_driver(this->Form
, REQ_SCR_FLINE
);
194 else if ( key
== KEY_UP
|| key
== ctrl('p') )
196 form_driver(this->Form
, REQ_SCR_BLINE
);
198 else if ( key
== KEY_NPAGE
|| key
== ctrl('d') )
200 form_driver(this->Form
, REQ_SCR_FPAGE
);
202 else if ( key
== KEY_PPAGE
|| key
== ctrl('u') )
204 form_driver(this->Form
, REQ_SCR_BPAGE
);
207 this->UpdateStatusBar();