Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""LICENSE 

2Copyright 2018 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of bokkichat. 

5 

6bokkichat is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11bokkichat is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with bokkichat. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20from typing import List, Type 

21from bokkichat.entities.Address import Address 

22from bokkichat.entities.message.Message import Message 

23from bokkichat.entities.message.TextMessage import TextMessage 

24from bokkichat.connection.Connection import Connection 

25from bokkichat.settings.impl.CliSettings import CliSettings 

26 

27 

28class CliConnection(Connection): 

29 """ 

30 Class that implements a CLI connection which can be used in testing 

31 """ 

32 

33 @classmethod 

34 def name(cls) -> str: 

35 """ 

36 The name of the connection class 

37 :return: The connection class name 

38 """ 

39 return "cli" 

40 

41 @property 

42 def address(self) -> Address: 

43 """ 

44 A CLI connection has no real entities, 

45 so a dummy entities is generated. 

46 :return: The entities of the connection 

47 """ 

48 return Address("CLI") 

49 

50 @classmethod 

51 def settings_cls(cls) -> Type[CliSettings]: 

52 """ 

53 The settings class used by this connection 

54 :return: The settings class 

55 """ 

56 return CliSettings 

57 

58 # noinspection PyMethodMayBeStatic 

59 def send(self, message: Message): 

60 """ 

61 Prints a "sent" message 

62 :param message: The message to "send" 

63 :return: None 

64 """ 

65 print(message) 

66 

67 def receive(self) -> List[Message]: 

68 """ 

69 A CLI Connection receives messages by listening to the input 

70 :return: A list of pending Message objects 

71 """ 

72 return [TextMessage(self.address, self.address, input())] 

73 

74 def close(self): 

75 """ 

76 Disconnects the Connection. 

77 :return: None 

78 """ 

79 pass