diff options
| author | Eugen Wissner <belka@caraus.de> | 2025-11-23 17:05:53 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2025-11-23 17:05:53 +0100 |
| commit | f3b3d4b1a26eba872c32ad95fc112650011b625c (patch) | |
| tree | 483c90b08fb640f9f96b83393f64af9b7e752984 /pharo-mooc/tiny-chat/src/TinyChat-client/TCConsole.class.st | |
| parent | bf11813e4fa859a4833cab226c4ea560765d6d77 (diff) | |
| download | book-exercises-f3b3d4b1a26eba872c32ad95fc112650011b625c.tar.gz | |
Add the tiny-chat project from the Pharo MOOC
Diffstat (limited to 'pharo-mooc/tiny-chat/src/TinyChat-client/TCConsole.class.st')
| -rw-r--r-- | pharo-mooc/tiny-chat/src/TinyChat-client/TCConsole.class.st | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/pharo-mooc/tiny-chat/src/TinyChat-client/TCConsole.class.st b/pharo-mooc/tiny-chat/src/TinyChat-client/TCConsole.class.st new file mode 100644 index 0000000..3f7055e --- /dev/null +++ b/pharo-mooc/tiny-chat/src/TinyChat-client/TCConsole.class.st @@ -0,0 +1,62 @@ +Class { + #name : 'TCConsole', + #superclass : 'SpPresenter', + #instVars : [ + 'chat', + 'list', + 'input' + ], + #category : 'TinyChat-client', + #package : 'TinyChat-client' +} + +{ #category : 'as yet unclassified' } +TCConsole class >> attach: aTinyChat [ + + | window | + window := self new chat: aTinyChat. + window open whenClosedDo: [ aTinyChat disconnect ]. + ^ window +] + +{ #category : 'as yet unclassified' } +TCConsole class >> defaultLayout [ + ^ SpBoxLayout newTopToBottom + add: #list; add: #input; yourself +] + +{ #category : 'accessing' } +TCConsole >> chat: anObject [ + chat := anObject +] + +{ #category : 'accessing' } +TCConsole >> initializeWidgets [ + + list := SpListPresenter new. + input := SpTextInputFieldPresenter new + placeholder: 'Type your message here...'; + enabled: true; + whenSubmitDo: [ :string | chat send: string. input text: '' ]. + self focusOrder add: input +] + +{ #category : 'accessing' } +TCConsole >> input [ + ^ input +] + +{ #category : 'accessing' } +TCConsole >> list [ + ^ list +] + +{ #category : 'accessing' } +TCConsole >> print: aCollectionOfMessages [ + list items: (aCollectionOfMessages collect: [ :m | m printString ]) +] + +{ #category : 'accessing' } +TCConsole >> title [ + ^ 'TinyChat' +] |
