1
1
import * as React from 'react' ;
2
2
import * as dateFormat from 'dateformat' ;
3
3
import { postConstruct , injectable , inject } from 'inversify' ;
4
- import { ThemeConfig } from 'react-select/src/theme' ;
5
4
import { OptionsType } from 'react-select/src/types' ;
6
- import Select from 'react-select' ;
7
- import { Styles } from 'react-select/src/styles' ;
5
+ import { ArduinoSelect } from '../components/arduino-select' ;
8
6
import { ReactWidget , Message , Widget } from '@theia/core/lib/browser/widgets' ;
9
7
import { MonitorConfig } from '../../common/protocol/monitor-service' ;
10
8
import { MonitorModel } from './monitor-model' ;
@@ -74,11 +72,6 @@ export class MonitorWidget extends ReactWidget {
74
72
this . update ( ) ;
75
73
}
76
74
77
- onBeforeAttach ( msg : Message ) : void {
78
- super . onBeforeAttach ( msg ) ;
79
- this . clearConsole ( ) ;
80
- }
81
-
82
75
protected onAfterAttach ( msg : Message ) : void {
83
76
super . onAfterAttach ( msg ) ;
84
77
this . monitorConnection . autoConnect = true ;
@@ -131,8 +124,8 @@ export class MonitorWidget extends ReactWidget {
131
124
< SerialMonitorSendField onSend = { this . onSend } />
132
125
</ div >
133
126
< div className = 'config' >
134
- { this . renderSelectField ( 'arduino- serial-monitor-line-endings' , lineEndings , lineEnding , this . onChangeLineEnding ) }
135
- { this . renderSelectField ( 'arduino- serial-monitor-baud-rates' , baudRates , baudRate , this . onChangeBaudRate ) }
127
+ < ArduinoSelect className = ' serial-monitor-select' options = { lineEndings } defaultValue = { lineEnding } onChange = { this . onChangeLineEnding } />
128
+ < ArduinoSelect className = ' serial-monitor-select' options = { baudRates } defaultValue = { baudRate } onChange = { this . onChangeBaudRate } />
136
129
</ div >
137
130
</ div >
138
131
< div id = 'serial-monitor-output-container' >
@@ -155,67 +148,8 @@ export class MonitorWidget extends ReactWidget {
155
148
this . model . baudRate = option . value ;
156
149
}
157
150
158
- protected renderSelectField < T > (
159
- id : string ,
160
- options : OptionsType < SelectOption < T > > ,
161
- defaultValue : SelectOption < T > ,
162
- onChange : ( option : SelectOption < T > ) => void ) : React . ReactNode {
163
-
164
- const height = 25 ;
165
- const styles : Styles = {
166
- control : ( styles , state ) => ( {
167
- ...styles ,
168
- width : 200 ,
169
- color : 'var(--theia-ui-font-color1)'
170
- } ) ,
171
- dropdownIndicator : styles => ( {
172
- ...styles ,
173
- padding : 0
174
- } ) ,
175
- indicatorSeparator : ( ) => ( {
176
- display : 'none'
177
- } ) ,
178
- indicatorsContainer : ( ) => ( {
179
- padding : '0px 5px'
180
- } ) ,
181
- menu : styles => ( {
182
- ...styles ,
183
- marginTop : 0
184
- } )
185
- } ;
186
- const theme : ThemeConfig = theme => ( {
187
- ...theme ,
188
- borderRadius : 0 ,
189
- spacing : {
190
- controlHeight : height ,
191
- baseUnit : 2 ,
192
- menuGutter : 4
193
- } , colors : {
194
- ...theme . colors ,
195
- // `primary50`??? it's crazy but apparently, without this, we would get a light-blueish
196
- // color when selecting an option in the select by clicking and then not releasing the button.
197
- // https://react-select.com/styles#overriding-the-theme
198
- primary50 : 'var(--theia-accent-color4)' ,
199
- }
200
- } ) ;
201
- const DropdownIndicator = ( ) => < span className = 'fa fa-caret-down caret' /> ;
202
- return < Select
203
- options = { options }
204
- defaultValue = { defaultValue }
205
- onChange = { onChange }
206
- components = { { DropdownIndicator } }
207
- theme = { theme }
208
- styles = { styles }
209
- maxMenuHeight = { this . widgetHeight - 40 }
210
- classNamePrefix = 'sms'
211
- className = 'serial-monitor-select'
212
- id = { id }
213
- isSearchable = { false }
214
- />
215
- }
216
151
}
217
152
218
-
219
153
export namespace SerialMonitorSendField {
220
154
export interface Props {
221
155
readonly onSend : ( text : string ) => void
@@ -248,14 +182,12 @@ export class SerialMonitorSendField extends React.Component<SerialMonitorSendFie
248
182
< input
249
183
tabIndex = { - 1 }
250
184
ref = { ref => this . inputField = ref }
251
- type = 'text' id = 'serial-monitor-send'
185
+ id = 'serial-monitor-send'
186
+ type = 'text'
252
187
autoComplete = 'off'
253
188
value = { this . state . value }
254
189
onChange = { this . handleChange } />
255
190
< button className = 'button' onClick = { this . handleSubmit } > Send</ button >
256
- { /* <input className='btn' type='submit' value='Submit' />
257
- <form onSubmit={this.handleSubmit}>
258
- </form> */ }
259
191
</ React . Fragment >
260
192
}
261
193
@@ -268,6 +200,7 @@ export class SerialMonitorSendField extends React.Component<SerialMonitorSendFie
268
200
this . setState ( { value : '' } ) ;
269
201
event . preventDefault ( ) ;
270
202
}
203
+
271
204
}
272
205
273
206
export namespace SerialMonitorOutput {
@@ -279,6 +212,9 @@ export namespace SerialMonitorOutput {
279
212
280
213
export class SerialMonitorOutput extends React . Component < SerialMonitorOutput . Props > {
281
214
215
+ /**
216
+ * Do not touch it. It is used to be able to "follow" the serial monitor log.
217
+ */
282
218
protected anchor : HTMLElement | null ;
283
219
284
220
render ( ) {
0 commit comments