From f3b3d4b1a26eba872c32ad95fc112650011b625c Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 23 Nov 2025 17:05:53 +0100 Subject: Add the tiny-chat project from the Pharo MOOC --- .../src/TinyChat-client/TCConsole.class.st | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 pharo-mooc/tiny-chat/src/TinyChat-client/TCConsole.class.st (limited to 'pharo-mooc/tiny-chat/src/TinyChat-client/TCConsole.class.st') 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' +] -- cgit v1.2.3